Aktualizacja go, komentarze, drobne poprawki
This commit is contained in:
		@@ -34,6 +34,7 @@ func main() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	loop := func() {
 | 
						loop := func() {
 | 
				
			||||||
		ticker := time.NewTicker(250 * time.Millisecond)
 | 
							ticker := time.NewTicker(250 * time.Millisecond)
 | 
				
			||||||
 | 
							defer ticker.Stop()
 | 
				
			||||||
		for {
 | 
							for {
 | 
				
			||||||
			term.GoHome()
 | 
								term.GoHome()
 | 
				
			||||||
			front.PrintMe()
 | 
								front.PrintMe()
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										17
									
								
								term/term.go
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								term/term.go
									
									
									
									
									
								
							@@ -2,13 +2,16 @@ package term
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import "fmt"
 | 
					import "fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// CursorFlag is used as a parameter to function TurnCursor and
 | 
				
			||||||
 | 
					// describes if cursor should be displayed or not.
 | 
				
			||||||
type CursorFlag bool
 | 
					type CursorFlag bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	CursorOn  CursorFlag = true
 | 
						CursorOn  CursorFlag = true  // Cursor should be visible
 | 
				
			||||||
	CursorOff CursorFlag = false
 | 
						CursorOff CursorFlag = false // Cursor should be hidden
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TurnCursor turns the cursor on and off according to the parameter.
 | 
				
			||||||
func TurnCursor(onOff CursorFlag) {
 | 
					func TurnCursor(onOff CursorFlag) {
 | 
				
			||||||
	if onOff == CursorOn {
 | 
						if onOff == CursorOn {
 | 
				
			||||||
		fmt.Printf("\033[?25h")
 | 
							fmt.Printf("\033[?25h")
 | 
				
			||||||
@@ -17,40 +20,50 @@ func TurnCursor(onOff CursorFlag) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ClearScreen clears current screen.
 | 
				
			||||||
func ClearScreen() {
 | 
					func ClearScreen() {
 | 
				
			||||||
	fmt.Printf("\033[2J")
 | 
						fmt.Printf("\033[2J")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ResetTerminal resets terminal (ESC c)
 | 
				
			||||||
func ResetTerminal() {
 | 
					func ResetTerminal() {
 | 
				
			||||||
	fmt.Printf("\033c")
 | 
						fmt.Printf("\033c")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GoHome moves cursor to the home position (upper left corner)
 | 
				
			||||||
func GoHome() {
 | 
					func GoHome() {
 | 
				
			||||||
	fmt.Printf("\033[H")
 | 
						fmt.Printf("\033[H")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// SaveCursor saves curent position of the SaveCursor
 | 
				
			||||||
func SaveCursor() {
 | 
					func SaveCursor() {
 | 
				
			||||||
	fmt.Printf("\033[s")
 | 
						fmt.Printf("\033[s")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// RestoreCursor restore cursor to the position saved previously with SaveCursor().
 | 
				
			||||||
func RestoreCursor() {
 | 
					func RestoreCursor() {
 | 
				
			||||||
	fmt.Printf("\033[u")
 | 
						fmt.Printf("\033[u")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// EnableAlternateScreen switches the terminal to the alternative screen.
 | 
				
			||||||
 | 
					// The alternative screen doesn't have the scroll buffer.
 | 
				
			||||||
func EnableAlternateScreen() {
 | 
					func EnableAlternateScreen() {
 | 
				
			||||||
	fmt.Printf("\033[?1049h")
 | 
						fmt.Printf("\033[?1049h")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// DiableAlternateScreen switches the terminal to the primary screen.
 | 
				
			||||||
func DisableAlternateScreen() {
 | 
					func DisableAlternateScreen() {
 | 
				
			||||||
	fmt.Printf("\033[?1049l")
 | 
						fmt.Printf("\033[?1049l")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// StartFullscreen saves the cursor, enables alternate screen and clears it.
 | 
				
			||||||
func StartFullscreen() {
 | 
					func StartFullscreen() {
 | 
				
			||||||
	SaveCursor()
 | 
						SaveCursor()
 | 
				
			||||||
	EnableAlternateScreen()
 | 
						EnableAlternateScreen()
 | 
				
			||||||
	ClearScreen()
 | 
						ClearScreen()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// FinishFullscreen returns to the primary screen and restores the cursor.
 | 
				
			||||||
func FinishFullscreen() {
 | 
					func FinishFullscreen() {
 | 
				
			||||||
	DisableAlternateScreen()
 | 
						DisableAlternateScreen()
 | 
				
			||||||
	RestoreCursor()
 | 
						RestoreCursor()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user