summary refs log blame commit diff stats
path: root/uml/128002.diagram
blob: 3c359d4240e9db499293f2221b4b39ece9f06838 (plain) (tree)
ass="p">(err) return } term.start <- nil } term.ctx = ctx // gross rows, cols, err := pty.Getsize(term.pty) if err != nil { return } if ctx.Width() != cols || ctx.Height() != rows { pty.Setsize(term.pty, &winsize) term.vterm.SetSize(ctx.Height(), ctx.Width()) return } screen := term.vterm.ObtainScreen() screen.Flush() type coords struct { x int y int } // naive optimization visited := make(map[coords]interface{}) for _, rect := range term.damage { for x := rect.StartCol(); x < rect.EndCol() && x < ctx.Width(); x += 1 { for y := rect.StartCol(); y < rect.EndCol() && y < ctx.Height(); y += 1 { coords := coords{x, y} if _, ok := visited[coords]; ok { continue } visited[coords] = nil cell, err := screen.GetCellAt(y, x) if err != nil { continue } style := term.styleFromCell(cell) ctx.Printf(x, y, style, "%s", string(cell.Chars())) } } } if !term.cursorShown { ctx.HideCursor() } else { row, col := term.vterm.ObtainState().GetCursorPos() ctx.SetCursor(col, row) } } func (term *Terminal) Focus(focus bool) { term.focus = focus } func convertMods(mods tcell.ModMask) vterm.Modifier { var ( ret uint = 0 mask uint = uint(mods) ) if mask&uint(tcell.ModShift) > 0 { ret |= uint(vterm.ModShift) } if mask&uint(tcell.ModCtrl) > 0 { ret |= uint(vterm.ModCtrl) } if mask&uint(tcell.ModAlt) > 0 { ret |= uint(vterm.ModAlt) } return vterm.Modifier(ret) } func (term *Terminal) Event(event tcell.Event) bool { switch event := event.(type) { case *tcell.EventKey: if event.Key() == tcell.KeyRune { term.vterm.KeyboardUnichar( event.Rune(), convertMods(event.Modifiers())) } else { if key, ok := keyMap[event.Key()]; ok { if key.Key == vterm.KeyNone { term.vterm.KeyboardUnichar( key.Rune, key.Mod) } else if key.Mod == vterm.ModNone { term.vterm.KeyboardKey(key.Key, convertMods(event.Modifiers())) } else { term.vterm.KeyboardKey(key.Key, key.Mod) } } } term.flushTerminal() } return false } func (term *Terminal) styleFromCell(cell *vterm.ScreenCell) tcell.Style { style := tcell.StyleDefault background := cell.Bg() r, g, b := background.GetRGB() bg := tcell.NewRGBColor(int32(r), int32(g), int32(b)) foreground := cell.Fg() r, g, b = foreground.GetRGB() fg := tcell.NewRGBColor(int32(r), int32(g), int32(b)) if color, ok := term.colors[bg]; ok { style = style.Background(color) } else { style = style.Background(bg) } if color, ok := term.colors[fg]; ok { style = style.Foreground(color) } else { style = style.Foreground(fg) } if cell.Attrs().Bold != 0 { style = style.Bold(true) } if cell.Attrs().Underline != 0 { style = style.Underline(true) } if cell.Attrs().Blink != 0 { style = style.Blink(true) } if cell.Attrs().Reverse != 0 { style = style.Reverse(true) } return style } func (term *Terminal) onDamage(rect *vterm.Rect) int { term.damage = append(term.damage, *rect) term.Invalidate() return 1 } func (term *Terminal) onMoveCursor(old *vterm.Pos, pos *vterm.Pos, visible bool) int { term.cursorShown = visible return 1 } func (term *Terminal) onSetTermProp(prop int, val *vterm.VTermValue) int { switch prop { case vterm.VTERM_PROP_TITLE: if term.OnTitle != nil { term.OnTitle(val.String) } } return 1 }