66)
77
88const (
9+ // Cursor positioning.
910 CursorUpSeq = "%dA"
1011 CursorDownSeq = "%dB"
1112 CursorForwardSeq = "%dC"
@@ -29,8 +30,7 @@ const (
2930 EraseLineLeftSeq = "1K"
3031 EraseEntireLineSeq = "2K"
3132
32- ShowCursorSeq = "?25h"
33- HideCursorSeq = "?25l"
33+ // Mouse.
3434 EnableMousePressSeq = "?9h" // press only (X10)
3535 DisableMousePressSeq = "?9l"
3636 EnableMouseSeq = "?1000h" // press, release, wheel
@@ -41,15 +41,52 @@ const (
4141 DisableMouseCellMotionSeq = "?1002l"
4242 EnableMouseAllMotionSeq = "?1003h" // press, release, move, wheel
4343 DisableMouseAllMotionSeq = "?1003l"
44- AltScreenSeq = "?1049h"
45- ExitAltScreenSeq = "?1049l"
44+
45+ // Screen.
46+ RestoreScreenSeq = "?47l"
47+ SaveScreenSeq = "?47h"
48+ AltScreenSeq = "?1049h"
49+ ExitAltScreenSeq = "?1049l"
50+
51+ // Session.
52+ SetWindowTitleSeq = "2;%s\007 "
53+ SetForegroundColorSeq = "10;%s\007 "
54+ SetBackgroundColorSeq = "11;%s\007 "
55+ SetCursorColorSeq = "12;%s\007 "
56+ ShowCursorSeq = "?25h"
57+ HideCursorSeq = "?25l"
4658)
4759
4860// Reset the terminal to its default style, removing any active styles.
4961func Reset () {
5062 fmt .Print (CSI + ResetSeq + "m" )
5163}
5264
65+ // SetForegroundColor sets the default foreground color.
66+ func SetForegroundColor (color Color ) {
67+ fmt .Printf (OSC + SetForegroundColorSeq , color )
68+ }
69+
70+ // SetBackgroundColor sets the default background color.
71+ func SetBackgroundColor (color Color ) {
72+ fmt .Printf (OSC + SetBackgroundColorSeq , color )
73+ }
74+
75+ // SetCursorColor sets the cursor color.
76+ func SetCursorColor (color Color ) {
77+ fmt .Printf (OSC + SetCursorColorSeq , color )
78+ }
79+
80+ // RestoreScreen restores a previously saved screen state.
81+ func RestoreScreen () {
82+ fmt .Print (CSI + RestoreScreenSeq )
83+ }
84+
85+ // SaveScreen saves the screen state.
86+ func SaveScreen () {
87+ fmt .Print (CSI + SaveScreenSeq )
88+ }
89+
5390// AltScreen switches to the alternate screen buffer. The former view can be
5491// restored with ExitAltScreen().
5592func AltScreen () {
@@ -213,3 +250,8 @@ func EnableMouseAllMotion() {
213250func DisableMouseAllMotion () {
214251 fmt .Print (CSI + DisableMouseAllMotionSeq )
215252}
253+
254+ // SetWindowTitle sets the terminal window title.
255+ func SetWindowTitle (title string ) {
256+ fmt .Printf (OSC + SetWindowTitleSeq , title )
257+ }
0 commit comments