mirror of
https://github.com/charmbracelet/glow
synced 2024-12-14 06:02:27 +00:00
Consolidate debug config stuff
This commit is contained in:
parent
fa06996383
commit
6e72cbdc4f
5 changed files with 40 additions and 19 deletions
3
go.mod
3
go.mod
|
@ -8,9 +8,10 @@ require (
|
||||||
github.com/charmbracelet/charm v0.5.1
|
github.com/charmbracelet/charm v0.5.1
|
||||||
github.com/charmbracelet/glamour v0.2.0
|
github.com/charmbracelet/glamour v0.2.0
|
||||||
github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac
|
github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac
|
||||||
|
github.com/mattn/go-runewidth v0.0.9
|
||||||
|
github.com/meowgorithm/babyenv v1.2.1
|
||||||
github.com/muesli/reflow v0.1.0
|
github.com/muesli/reflow v0.1.0
|
||||||
github.com/muesli/termenv v0.6.0
|
github.com/muesli/termenv v0.6.0
|
||||||
github.com/mattn/go-runewidth v0.0.9
|
|
||||||
github.com/spf13/cobra v0.0.7
|
github.com/spf13/cobra v0.0.7
|
||||||
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9
|
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9
|
||||||
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2 // indirect
|
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2 // indirect
|
||||||
|
|
3
go.sum
3
go.sum
|
@ -20,7 +20,6 @@ github.com/charmbracelet/bubbles v0.2.0 h1:2tGD++FxmPUZ+DLjVcpx6HvuJ5HwlmUw2vLF9
|
||||||
github.com/charmbracelet/bubbles v0.2.0/go.mod h1:RA4uIEHJqv5AJuFGbjB+5YrdNJk4rsi3qxBpdHScBLY=
|
github.com/charmbracelet/bubbles v0.2.0/go.mod h1:RA4uIEHJqv5AJuFGbjB+5YrdNJk4rsi3qxBpdHScBLY=
|
||||||
github.com/charmbracelet/bubbletea v0.6.4-0.20200525234836-3b8b011b5a26/go.mod h1:BTzHOUvUlKecQz7ZB8NgPRWi2Z8NRCV04qwyFOfO1Kk=
|
github.com/charmbracelet/bubbletea v0.6.4-0.20200525234836-3b8b011b5a26/go.mod h1:BTzHOUvUlKecQz7ZB8NgPRWi2Z8NRCV04qwyFOfO1Kk=
|
||||||
github.com/charmbracelet/bubbletea v0.7.0/go.mod h1:BTzHOUvUlKecQz7ZB8NgPRWi2Z8NRCV04qwyFOfO1Kk=
|
github.com/charmbracelet/bubbletea v0.7.0/go.mod h1:BTzHOUvUlKecQz7ZB8NgPRWi2Z8NRCV04qwyFOfO1Kk=
|
||||||
github.com/charmbracelet/bubbletea v0.8.0 h1:ruZFaFF+2kgCI1IwNG40KTYDW5ZvE2+hPy4odlBdUko=
|
|
||||||
github.com/charmbracelet/bubbletea v0.8.0/go.mod h1:DzNhKkQQJI30eb+kBcaOs1+z86zTSqcMgSHoFY+uCsg=
|
github.com/charmbracelet/bubbletea v0.8.0/go.mod h1:DzNhKkQQJI30eb+kBcaOs1+z86zTSqcMgSHoFY+uCsg=
|
||||||
github.com/charmbracelet/bubbletea v0.8.1 h1:Q7qdKOl4LJa9QV/LDwFWa9DFlZwwJkQipXrrfu/+dJM=
|
github.com/charmbracelet/bubbletea v0.8.1 h1:Q7qdKOl4LJa9QV/LDwFWa9DFlZwwJkQipXrrfu/+dJM=
|
||||||
github.com/charmbracelet/bubbletea v0.8.1/go.mod h1:DzNhKkQQJI30eb+kBcaOs1+z86zTSqcMgSHoFY+uCsg=
|
github.com/charmbracelet/bubbletea v0.8.1/go.mod h1:DzNhKkQQJI30eb+kBcaOs1+z86zTSqcMgSHoFY+uCsg=
|
||||||
|
@ -153,7 +152,6 @@ go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/
|
||||||
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
||||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 h1:cg5LA/zNPRzIXIWSCxQW10Rvpy94aQh3LT/ShoCpkHw=
|
|
||||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM=
|
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM=
|
||||||
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
@ -183,7 +181,6 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||||
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 h1:OjiUf46hAmXblsZdnoSXsEUSKU8r1UEzcL5RVZ4gO9Y=
|
|
||||||
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80=
|
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80=
|
||||||
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
|
18
main.go
18
main.go
|
@ -12,6 +12,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/meowgorithm/babyenv"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/crypto/ssh/terminal"
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
|
|
||||||
|
@ -168,22 +169,29 @@ func executeArg(cmd *cobra.Command, arg string, w io.Writer) error {
|
||||||
// Only run TUI if there are no arguments (excluding flags)
|
// Only run TUI if there are no arguments (excluding flags)
|
||||||
if arg == "" {
|
if arg == "" {
|
||||||
|
|
||||||
// Log to a file. For debugging.
|
// Read environment to get debugging stuff
|
||||||
logToFilePath := os.Getenv("GLOW_LOG_TO_FILE")
|
var cfg ui.UIConfig
|
||||||
if logToFilePath != "" {
|
if err := babyenv.Parse(&cfg); err != nil {
|
||||||
f, err := tea.LogToFile(logToFilePath, "glow")
|
return fmt.Errorf("error parsing config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log to file, if set
|
||||||
|
if cfg.Logfile != "" {
|
||||||
|
f, err := tea.LogToFile(cfg.Logfile, "glow")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run Bubble Tea program
|
||||||
tea.AltScreen()
|
tea.AltScreen()
|
||||||
if err := ui.NewProgram(style).Start(); err != nil {
|
if err := ui.NewProgram(style, cfg).Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tea.ExitAltScreen()
|
tea.ExitAltScreen()
|
||||||
|
|
||||||
|
// Exit message
|
||||||
fmt.Printf("\n Thanks for using Glow!\n\n")
|
fmt.Printf("\n Thanks for using Glow!\n\n")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
17
ui/pager.go
17
ui/pager.go
|
@ -4,7 +4,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/textinput"
|
"github.com/charmbracelet/bubbles/textinput"
|
||||||
|
@ -28,9 +27,6 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Whether or not to use fast scroll-based rendering for the viewport
|
|
||||||
highPerformanceRendering = true
|
|
||||||
|
|
||||||
pagerHelpHeight = strings.Count(pagerHelpView(0), "\n")
|
pagerHelpHeight = strings.Count(pagerHelpView(0), "\n")
|
||||||
|
|
||||||
noteHeading = te.String(noteHeadingText).
|
noteHeading = te.String(noteHeadingText).
|
||||||
|
@ -93,6 +89,13 @@ type pagerModel struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPagerModel(glamourStyle string) pagerModel {
|
func newPagerModel(glamourStyle string) pagerModel {
|
||||||
|
|
||||||
|
// Init viewport
|
||||||
|
vp := viewport.Model{}
|
||||||
|
vp.YPosition = 0
|
||||||
|
vp.HighPerformanceRendering = config.HighPerformancePager
|
||||||
|
|
||||||
|
// Init text input UI for notes/memos
|
||||||
ti := textinput.NewModel()
|
ti := textinput.NewModel()
|
||||||
ti.Prompt = te.String(notePromptText).
|
ti.Prompt = te.String(notePromptText).
|
||||||
Foreground(te.ColorProfile().Color(gray)).
|
Foreground(te.ColorProfile().Color(gray)).
|
||||||
|
@ -104,10 +107,6 @@ func newPagerModel(glamourStyle string) pagerModel {
|
||||||
ti.CharLimit = noteCharacterLimit
|
ti.CharLimit = noteCharacterLimit
|
||||||
ti.Focus()
|
ti.Focus()
|
||||||
|
|
||||||
vp := viewport.Model{}
|
|
||||||
vp.YPosition = 0
|
|
||||||
vp.HighPerformanceRendering = highPerformanceRendering
|
|
||||||
|
|
||||||
return pagerModel{
|
return pagerModel{
|
||||||
state: pagerStateBrowse,
|
state: pagerStateBrowse,
|
||||||
glamourStyle: glamourStyle,
|
glamourStyle: glamourStyle,
|
||||||
|
@ -350,7 +349,7 @@ func saveDocumentNote(cc *charm.Client, id int, note string) tea.Cmd {
|
||||||
// This is where the magic happens
|
// This is where the magic happens
|
||||||
func glamourRender(m pagerModel, markdown string) (string, error) {
|
func glamourRender(m pagerModel, markdown string) (string, error) {
|
||||||
|
|
||||||
if os.Getenv("GLOW_DISABLE_GLAMOUR") != "" {
|
if !config.GlamourEnabled {
|
||||||
return markdown, nil
|
return markdown, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
ui/ui.go
18
ui/ui.go
|
@ -3,6 +3,7 @@ package ui
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/spinner"
|
"github.com/charmbracelet/bubbles/spinner"
|
||||||
|
@ -17,12 +18,27 @@ const (
|
||||||
noteCharacterLimit = 256 // totally arbitrary
|
noteCharacterLimit = 256 // totally arbitrary
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// UIConfig contains flags for debugging the TUI.
|
||||||
|
type UIConfig struct {
|
||||||
|
Logfile string `env:"GLOW_UI_LOGFILE"`
|
||||||
|
HighPerformancePager bool `env:"GLOW_UI_HIGH_PERFORMANCE_PAGER" default:"true"`
|
||||||
|
GlamourEnabled bool `env:"GLOW_UI_ENABLE_GLAMOUR" default:"true"`
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
config UIConfig
|
||||||
glowLogoTextColor = common.Color("#ECFD65")
|
glowLogoTextColor = common.Color("#ECFD65")
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewProgram returns a new Tea program
|
// NewProgram returns a new Tea program
|
||||||
func NewProgram(style string) *tea.Program {
|
func NewProgram(style string, cfg UIConfig) *tea.Program {
|
||||||
|
config = cfg
|
||||||
|
if config.Logfile != "" {
|
||||||
|
log.Println("-- Starting Glow ----------------")
|
||||||
|
log.Printf("High performance pager: %v", cfg.HighPerformancePager)
|
||||||
|
log.Printf("Render with Glamour: %v", cfg.GlamourEnabled)
|
||||||
|
log.Println("Bubble Tea now initializing...")
|
||||||
|
}
|
||||||
return tea.NewProgram(initialize(style), update, view)
|
return tea.NewProgram(initialize(style), update, view)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue