mirror of
https://github.com/charmbracelet/glow
synced 2025-03-04 14:57:13 +00:00
Respect -i/--identity flag in the TUI
This commit is contained in:
parent
956fc9ec57
commit
fa7c8f09f9
4 changed files with 40 additions and 27 deletions
2
go.mod
2
go.mod
|
@ -5,7 +5,7 @@ go 1.13
|
|||
require (
|
||||
github.com/charmbracelet/bubbles v0.5.1
|
||||
github.com/charmbracelet/bubbletea v0.10.3-0.20200727185851-c6a1afd3c79c
|
||||
github.com/charmbracelet/charm v0.5.3-0.20200804221332-0d6911bec999
|
||||
github.com/charmbracelet/charm v0.5.3-0.20200807155853-9fd04eeb7cae
|
||||
github.com/charmbracelet/glamour v0.1.1-0.20200521150359-e859bb067c06
|
||||
github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac
|
||||
github.com/mattn/go-runewidth v0.0.9
|
||||
|
|
4
go.sum
4
go.sum
|
@ -23,8 +23,8 @@ github.com/charmbracelet/bubbletea v0.9.1-0.20200713153904-2f53eeb54b90/go.mod h
|
|||
github.com/charmbracelet/bubbletea v0.10.2/go.mod h1:wjGGC5pyYvpuls0so+w4Zv+aZQW7RoPvsi9UBcDlSl8=
|
||||
github.com/charmbracelet/bubbletea v0.10.3-0.20200727185851-c6a1afd3c79c h1:nb4KGAydLS6q3277+IqZLCGFNO2tdwrSKZ75AXAnnUI=
|
||||
github.com/charmbracelet/bubbletea v0.10.3-0.20200727185851-c6a1afd3c79c/go.mod h1:wjGGC5pyYvpuls0so+w4Zv+aZQW7RoPvsi9UBcDlSl8=
|
||||
github.com/charmbracelet/charm v0.5.3-0.20200804221332-0d6911bec999 h1:A7QpVVwsdTHJzYptFEOCgEIHw0wSc+v5gk43XtbNJ5w=
|
||||
github.com/charmbracelet/charm v0.5.3-0.20200804221332-0d6911bec999/go.mod h1:oVGSjOFSAP20xua6zWXn6F1WC0cf5UYvZAYfgi1T/h0=
|
||||
github.com/charmbracelet/charm v0.5.3-0.20200807155853-9fd04eeb7cae h1:ADpWgyN9GapfrQ50tSEWty//z76XDQ8i4lhlsn0i1eY=
|
||||
github.com/charmbracelet/charm v0.5.3-0.20200807155853-9fd04eeb7cae/go.mod h1:oVGSjOFSAP20xua6zWXn6F1WC0cf5UYvZAYfgi1T/h0=
|
||||
github.com/charmbracelet/glamour v0.1.1-0.20200521150359-e859bb067c06 h1:FR5F7kH6i4Jm0+5ypNWWFKVcH07hIO3aGNuDXnOdWqY=
|
||||
github.com/charmbracelet/glamour v0.1.1-0.20200521150359-e859bb067c06/go.mod h1:ECr5vYu2tKCePqAbZNUh94HiZDPMtbc9ggAy4n585JU=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
|
|
7
main.go
7
main.go
|
@ -170,11 +170,14 @@ func executeArg(cmd *cobra.Command, arg string, w io.Writer) error {
|
|||
if arg == "" {
|
||||
|
||||
// Read environment to get debugging stuff
|
||||
var cfg ui.UIConfig
|
||||
var cfg ui.Config
|
||||
if err := babyenv.Parse(&cfg); err != nil {
|
||||
return fmt.Errorf("error parsing config: %v", err)
|
||||
}
|
||||
|
||||
// Config from flags
|
||||
cfg.IdentityFile = identityFile
|
||||
|
||||
// Log to file, if set
|
||||
if cfg.Logfile != "" {
|
||||
f, err := tea.LogToFile(cfg.Logfile, "glow")
|
||||
|
@ -292,7 +295,7 @@ func init() {
|
|||
|
||||
// For network-related operations, namely stashing and the TUI
|
||||
rootCmd.PersistentFlags().StringVarP(&identityFile, "identity", "i", "", "path to identity file (that is, an ssh private key)")
|
||||
rootCmd.PersistentFlags().BoolVarP(&forceKey, "force-key", "f", false, "for the use of the SSH key on disk (that is, ignore ssh-agent)")
|
||||
rootCmd.PersistentFlags().BoolVarP(&forceKey, "force-key", "f", false, "force the use of the SSH key on disk (that is, ignore ssh-agent)")
|
||||
|
||||
// Stash
|
||||
stashCmd.PersistentFlags().StringVarP(&memo, "memo", "m", "", "memo/note for stashing")
|
||||
|
|
54
ui/ui.go
54
ui/ui.go
|
@ -19,28 +19,30 @@ const (
|
|||
noteCharacterLimit = 256 // should match server
|
||||
)
|
||||
|
||||
// UIConfig contains flags for debugging the TUI.
|
||||
type UIConfig struct {
|
||||
// Config contains configuration specified to the TUI
|
||||
type Config struct {
|
||||
IdentityFile string
|
||||
|
||||
// For debugging the UI
|
||||
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 (
|
||||
config UIConfig
|
||||
config Config
|
||||
glowLogoTextColor = common.Color("#ECFD65")
|
||||
)
|
||||
|
||||
// NewProgram returns a new Tea program
|
||||
func NewProgram(style string, cfg UIConfig) *tea.Program {
|
||||
config = cfg
|
||||
if config.Logfile != "" {
|
||||
func NewProgram(style string, cfg Config) *tea.Program {
|
||||
if cfg.Logfile != "" {
|
||||
log.Println("-- Starting Glow ----------------")
|
||||
log.Printf("High performance pager: %v", cfg.HighPerformancePager)
|
||||
log.Printf("Glamour rendering: %v", cfg.GlamourEnabled)
|
||||
log.Println("Bubble Tea now initializing...")
|
||||
}
|
||||
return tea.NewProgram(initialize(style), update, view)
|
||||
return tea.NewProgram(initialize(cfg, style), update, view)
|
||||
}
|
||||
|
||||
// MESSAGES
|
||||
|
@ -88,6 +90,7 @@ const (
|
|||
)
|
||||
|
||||
type model struct {
|
||||
cfg Config
|
||||
cc *charm.Client
|
||||
user *charm.User
|
||||
keygenState keygenState
|
||||
|
@ -124,7 +127,7 @@ func (m *model) unloadDocument() []tea.Cmd {
|
|||
|
||||
// INIT
|
||||
|
||||
func initialize(style string) func() (tea.Model, tea.Cmd) {
|
||||
func initialize(cfg Config, style string) func() (tea.Model, tea.Cmd) {
|
||||
return func() (tea.Model, tea.Cmd) {
|
||||
if style == "auto" {
|
||||
dbg := te.HasDarkBackground()
|
||||
|
@ -136,6 +139,7 @@ func initialize(style string) func() (tea.Model, tea.Cmd) {
|
|||
}
|
||||
|
||||
m := model{
|
||||
cfg: cfg,
|
||||
stash: newStashModel(),
|
||||
pager: newPagerModel(style),
|
||||
state: stateShowStash,
|
||||
|
@ -144,7 +148,7 @@ func initialize(style string) func() (tea.Model, tea.Cmd) {
|
|||
|
||||
return m, tea.Batch(
|
||||
findLocalFiles,
|
||||
newCharmClient,
|
||||
newCharmClient(&cfg.IdentityFile),
|
||||
spinner.Tick(m.stash.spinner),
|
||||
)
|
||||
}
|
||||
|
@ -279,7 +283,7 @@ func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
|
|||
case keygenSuccessMsg:
|
||||
// The keygen's done, so let's try initializing the charm client again
|
||||
m.keygenState = keygenFinished
|
||||
cmds = append(cmds, newCharmClient)
|
||||
cmds = append(cmds, newCharmClient(nil))
|
||||
|
||||
case newCharmClientMsg:
|
||||
m.cc = msg
|
||||
|
@ -395,20 +399,26 @@ func findNextLocalFile(m model) tea.Cmd {
|
|||
}
|
||||
}
|
||||
|
||||
func newCharmClient() tea.Msg {
|
||||
cfg, err := charm.ConfigFromEnv()
|
||||
if err != nil {
|
||||
return errMsg(err)
|
||||
}
|
||||
func newCharmClient(identityFile *string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
cfg, err := charm.ConfigFromEnv()
|
||||
if err != nil {
|
||||
return errMsg(err)
|
||||
}
|
||||
|
||||
cc, err := charm.NewClient(cfg)
|
||||
if err == charm.ErrMissingSSHAuth {
|
||||
return sshAuthErrMsg{}
|
||||
} else if err != nil {
|
||||
return errMsg(err)
|
||||
}
|
||||
if identityFile != nil {
|
||||
cfg.SSHKeyPath = *identityFile
|
||||
}
|
||||
|
||||
return newCharmClientMsg(cc)
|
||||
cc, err := charm.NewClient(cfg)
|
||||
if err == charm.ErrMissingSSHAuth {
|
||||
return sshAuthErrMsg{}
|
||||
} else if err != nil {
|
||||
return errMsg(err)
|
||||
}
|
||||
|
||||
return newCharmClientMsg(cc)
|
||||
}
|
||||
}
|
||||
|
||||
func loadStash(m stashModel) tea.Cmd {
|
||||
|
|
Loading…
Add table
Reference in a new issue