mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-15 19:28:00 +01:00
respond to optimal size feedback
This commit is contained in:
committed by
Marcin Kulik
parent
d32827b103
commit
a450a530c7
@@ -11,8 +11,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
optimalCols = 120
|
warnCols = 120
|
||||||
optimalRows = 30
|
warnRows = 30
|
||||||
)
|
)
|
||||||
|
|
||||||
type Recorder interface {
|
type Recorder interface {
|
||||||
@@ -30,7 +30,6 @@ func NewRecorder() Recorder {
|
|||||||
func (r *AsciicastRecorder) checkTerminalSize() chan<- bool {
|
func (r *AsciicastRecorder) checkTerminalSize() chan<- bool {
|
||||||
rows, cols, _ := r.Terminal.Size()
|
rows, cols, _ := r.Terminal.Size()
|
||||||
doneChan := make(chan bool)
|
doneChan := make(chan bool)
|
||||||
optimalSize := fmt.Sprintf("%s%dx%d%s", "\x1b[0m\x1b[32m", optimalCols, optimalRows, "\x1b[0m\x1b[33m")
|
|
||||||
go func() {
|
go func() {
|
||||||
winch := make(chan os.Signal, 1)
|
winch := make(chan os.Signal, 1)
|
||||||
signal.Notify(winch, syscall.SIGWINCH)
|
signal.Notify(winch, syscall.SIGWINCH)
|
||||||
@@ -46,10 +45,7 @@ func (r *AsciicastRecorder) checkTerminalSize() chan<- bool {
|
|||||||
if cols != newCols || rows != newRows {
|
if cols != newCols || rows != newRows {
|
||||||
cols, rows = newCols, newRows
|
cols, rows = newCols, newRows
|
||||||
currentSize := fmt.Sprintf("%dx%d", cols, rows)
|
currentSize := fmt.Sprintf("%dx%d", cols, rows)
|
||||||
if cols == optimalCols && rows == optimalRows {
|
util.ReplaceWarningf("Current terminal size is %s.", currentSize)
|
||||||
currentSize = fmt.Sprintf("%s%dx%d%s", "\x1b[0m\x1b[32m", cols, rows, "\x1b[0m\x1b[33m")
|
|
||||||
}
|
|
||||||
util.ReplaceWarningf("Current terminal size is %s. Optimal is %s.", currentSize, optimalSize)
|
|
||||||
}
|
}
|
||||||
case <-doneChan:
|
case <-doneChan:
|
||||||
return
|
return
|
||||||
@@ -63,10 +59,11 @@ func (r *AsciicastRecorder) Record(path, command, title string, maxWait float64,
|
|||||||
// TODO: touch savePath to ensure writing is possible
|
// TODO: touch savePath to ensure writing is possible
|
||||||
|
|
||||||
rows, cols, _ := r.Terminal.Size()
|
rows, cols, _ := r.Terminal.Size()
|
||||||
if rows != optimalRows || cols != optimalCols {
|
if rows > warnRows || cols > warnCols {
|
||||||
if !assumeYes {
|
if !assumeYes {
|
||||||
doneChan := r.checkTerminalSize()
|
doneChan := r.checkTerminalSize()
|
||||||
util.Warningf("Current terminal size is %vx%v. Optimal is %vx%v", cols, rows, optimalCols, optimalRows)
|
util.Warningf("Current terminal size is %vx%v.", cols, rows)
|
||||||
|
util.Warningf("It may be too big to be properly replayed on smaller screens.")
|
||||||
util.Warningf("You can now resize it. Press <Enter> to start recording.")
|
util.Warningf("You can now resize it. Press <Enter> to start recording.")
|
||||||
util.ReadLine()
|
util.ReadLine()
|
||||||
doneChan <- true
|
doneChan <- true
|
||||||
|
|||||||
Reference in New Issue
Block a user