mods/term.go

34 lines
705 B
Go
Raw Normal View History

feat: improve --continue, --show, auto-save, and added a db (#95) * feat: improve --continue and auto-save Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: load from one file, save to another * fix: last line of output being eaten * feat: --show Reimplemented #92 using over this branch as it had too many conflicts. closes #92 * fix: mods with no args, mods --delete * fix: continue should not save empty filename * feat: --list show the beginning of the last prompt * fix: do not write on show * feat: use a sqlite db Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: no cgo * fix: first line of the prompt only * refactor: open db * fix: --continue duplicating creating a new id * refactor: improve cache code * fix: crypto/rand instead of math's * fix: close db on exit * fix: style Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * test: added db_test.go Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * test: add cache_test.go * test: add messages_test.go * fix: use goreleaser-mods.yaml * fix: line breaks Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * refactor: improvements * fix: wrong import * chore: missplaced commend * refactor: improving main.go * fix: auto-glamour * fix: extra empty line * test: cacheops Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * test: windows Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: stream output to stdout if ouput is not a terminal also lazily cached the isatty and isaterm checks, using sync.OnceValue. PS: this will disable the loading indicator when the output is not a term. * fix: std db name Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * wip: render * fix: first char and last line Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: rename Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: donestate Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: dep Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: quiet Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: saving without a message * fix: simplify stdout check * docs: adding a document specifying how mods should behave in each case This should help us test it and also clarifies the expectations to the users. Very WIP. * refactor: rename func * docs: update * fix: trim spaces not sure if this looks better or worse tbh) Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * test: skip on windows Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: improve db Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * chore: typo * test: reenable on windows --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2023-08-11 17:21:11 +00:00
package main
import (
"os"
2023-09-05 23:13:19 +00:00
"github.com/charmbracelet/lipgloss"
feat: improve --continue, --show, auto-save, and added a db (#95) * feat: improve --continue and auto-save Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: load from one file, save to another * fix: last line of output being eaten * feat: --show Reimplemented #92 using over this branch as it had too many conflicts. closes #92 * fix: mods with no args, mods --delete * fix: continue should not save empty filename * feat: --list show the beginning of the last prompt * fix: do not write on show * feat: use a sqlite db Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: no cgo * fix: first line of the prompt only * refactor: open db * fix: --continue duplicating creating a new id * refactor: improve cache code * fix: crypto/rand instead of math's * fix: close db on exit * fix: style Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * test: added db_test.go Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * test: add cache_test.go * test: add messages_test.go * fix: use goreleaser-mods.yaml * fix: line breaks Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * refactor: improvements * fix: wrong import * chore: missplaced commend * refactor: improving main.go * fix: auto-glamour * fix: extra empty line * test: cacheops Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * test: windows Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: stream output to stdout if ouput is not a terminal also lazily cached the isatty and isaterm checks, using sync.OnceValue. PS: this will disable the loading indicator when the output is not a term. * fix: std db name Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * wip: render * fix: first char and last line Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: rename Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: donestate Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: dep Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: quiet Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: saving without a message * fix: simplify stdout check * docs: adding a document specifying how mods should behave in each case This should help us test it and also clarifies the expectations to the users. Very WIP. * refactor: rename func * docs: update * fix: trim spaces not sure if this looks better or worse tbh) Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * test: skip on windows Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: improve db Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * chore: typo * test: reenable on windows --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2023-08-11 17:21:11 +00:00
"github.com/mattn/go-isatty"
2023-09-05 23:13:19 +00:00
"github.com/muesli/termenv"
feat: improve --continue, --show, auto-save, and added a db (#95) * feat: improve --continue and auto-save Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: load from one file, save to another * fix: last line of output being eaten * feat: --show Reimplemented #92 using over this branch as it had too many conflicts. closes #92 * fix: mods with no args, mods --delete * fix: continue should not save empty filename * feat: --list show the beginning of the last prompt * fix: do not write on show * feat: use a sqlite db Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: no cgo * fix: first line of the prompt only * refactor: open db * fix: --continue duplicating creating a new id * refactor: improve cache code * fix: crypto/rand instead of math's * fix: close db on exit * fix: style Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * test: added db_test.go Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * test: add cache_test.go * test: add messages_test.go * fix: use goreleaser-mods.yaml * fix: line breaks Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * refactor: improvements * fix: wrong import * chore: missplaced commend * refactor: improving main.go * fix: auto-glamour * fix: extra empty line * test: cacheops Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * test: windows Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: stream output to stdout if ouput is not a terminal also lazily cached the isatty and isaterm checks, using sync.OnceValue. PS: this will disable the loading indicator when the output is not a term. * fix: std db name Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * wip: render * fix: first char and last line Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: rename Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: donestate Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: dep Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: quiet Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: saving without a message * fix: simplify stdout check * docs: adding a document specifying how mods should behave in each case This should help us test it and also clarifies the expectations to the users. Very WIP. * refactor: rename func * docs: update * fix: trim spaces not sure if this looks better or worse tbh) Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * test: skip on windows Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: improve db Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * chore: typo * test: reenable on windows --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2023-08-11 17:21:11 +00:00
)
var isInputTTY = OnceValue(func() bool {
return isatty.IsTerminal(os.Stdin.Fd())
})
var isOutputTTY = OnceValue(func() bool {
return isatty.IsTerminal(os.Stdout.Fd())
})
2023-09-05 23:13:19 +00:00
var stdoutRenderer = OnceValue(func() *lipgloss.Renderer {
return lipgloss.DefaultRenderer()
})
var stdoutStyles = OnceValue(func() styles {
return makeStyles(stdoutRenderer())
})
var stderrRenderer = OnceValue(func() *lipgloss.Renderer {
return lipgloss.NewRenderer(os.Stderr, termenv.WithColorCache(true))
})
var stderrStyles = OnceValue(func() styles {
return makeStyles(stderrRenderer())
})