7 "github.com/zyedidia/tcell"
8 "github.com/zyedidia/terminal"
12 VTIdle = iota // Waiting for a new command
13 VTRunning // Currently running a command
14 VTDone // Finished running a command
17 // A Terminal holds information for the terminal emulator
18 type Terminal struct {
25 // Start begins a new command in this terminal with a given view
26 func (t *Terminal) Start(execCmd []string, view *View) error {
27 if len(execCmd) <= 0 {
31 cmd := exec.Command(execCmd[0], execCmd[1:]...)
32 term, _, err := terminal.Start(&t.state, cmd)
38 t.title = execCmd[0] + ":" + strconv.Itoa(cmd.Process.Pid)
54 // Resize informs the terminal of a resize event
55 func (t *Terminal) Resize(width, height int) {
56 t.term.Resize(width, height)
59 // Stop stops execution of the terminal and sets the status
61 func (t *Terminal) Stop() {
67 // Close sets the status to VTIdle indicating that the terminal
68 // is ready for a new command to execute
69 func (t *Terminal) Close() {
73 // WriteString writes a given string to this terminal's pty
74 func (t *Terminal) WriteString(str string) {
75 t.term.File().WriteString(str)
78 // Display displays this terminal in a view
79 func (t *Terminal) Display(v *View) {
83 dividerStyle := defStyle
84 if style, ok := colorscheme["divider"]; ok {
87 for i := 0; i < v.Height; i++ {
88 screen.SetContent(v.x, v.y+i, '|', nil, dividerStyle.Reverse(true))
92 defer t.state.Unlock()
94 for y := 0; y < v.Height; y++ {
95 for x := 0; x < v.Width; x++ {
97 c, f, b := t.state.Cell(x, y)
99 fg, bg := int(f), int(b)
100 if f == terminal.DefaultFG {
101 fg = int(tcell.ColorDefault)
103 if b == terminal.DefaultBG {
104 bg = int(tcell.ColorDefault)
106 st := tcell.StyleDefault.Foreground(GetColor256(int(fg))).Background(GetColor256(int(bg)))
108 screen.SetContent(v.x+x+divider, v.y+y, c, nil, st)
111 if t.state.CursorVisible() && tabs[curTab].CurView == v.Num {
112 curx, cury := t.state.Cursor()
113 screen.ShowCursor(curx+v.x+divider, cury+v.y)