4 "github.com/zyedidia/micro/v2/internal/buffer"
5 "github.com/zyedidia/micro/v2/internal/config"
6 "github.com/zyedidia/micro/v2/internal/screen"
7 "github.com/zyedidia/micro/v2/internal/shell"
8 "github.com/zyedidia/micro/v2/internal/util"
9 "github.com/zyedidia/tcell/v2"
10 "github.com/zyedidia/terminal"
13 type TermWindow struct {
20 func NewTermWindow(x, y, w, h int, term *shell.Terminal) *TermWindow {
29 // Resize informs the terminal of a resize event
30 func (w *TermWindow) Resize(width, height int) {
31 if config.GetGlobalOption("statusline").(bool) {
34 w.Term.Resize(width, height)
35 w.Width, w.Height = width, height
38 func (w *TermWindow) SetActive(b bool) {
42 func (w *TermWindow) IsActive() bool {
46 func (w *TermWindow) LocFromVisual(vloc buffer.Loc) buffer.Loc {
50 func (w *TermWindow) Clear() {
51 for y := 0; y < w.Height; y++ {
52 for x := 0; x < w.Width; x++ {
53 screen.SetContent(w.X+x, w.Y+y, ' ', nil, config.DefStyle)
58 func (w *TermWindow) Relocate() bool { return true }
59 func (w *TermWindow) GetView() *View {
62 func (w *TermWindow) SetView(v *View) {
66 // Display displays this terminal in a view
67 func (w *TermWindow) Display() {
69 defer w.State.Unlock()
72 for y := 0; y < w.Height; y++ {
73 for x := 0; x < w.Width; x++ {
75 c, f, b := w.State.Cell(x, y)
77 fg, bg := int(f), int(b)
78 if f == terminal.DefaultFG {
79 fg = int(tcell.ColorDefault)
81 if b == terminal.DefaultBG {
82 bg = int(tcell.ColorDefault)
84 st := tcell.StyleDefault.Foreground(config.GetColor256(fg)).Background(config.GetColor256(bg))
86 if l.LessThan(w.Selection[1]) && l.GreaterEqual(w.Selection[0]) || l.LessThan(w.Selection[0]) && l.GreaterEqual(w.Selection[1]) {
90 screen.SetContent(w.X+x, w.Y+y, c, nil, st)
93 if config.GetGlobalOption("statusline").(bool) {
94 statusLineStyle := config.DefStyle.Reverse(true)
95 if style, ok := config.Colorscheme["statusline"]; ok {
96 statusLineStyle = style
99 text := []byte(w.Name())
100 textLen := util.CharacterCount(text)
101 for x := 0; x < w.Width; x++ {
103 r, combc, size := util.DecodeCharacter(text)
105 screen.SetContent(w.X+x, w.Y+w.Height, r, combc, statusLineStyle)
107 screen.SetContent(w.X+x, w.Y+w.Height, ' ', nil, statusLineStyle)
111 if w.State.CursorVisible() && w.active {
112 curx, cury := w.State.Cursor()
113 screen.ShowCursor(curx+w.X, cury+w.Y)