mirror of
https://github.com/charmbracelet/glow
synced 2024-11-10 14:14:17 +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 (
|
require (
|
||||||
github.com/charmbracelet/bubbles v0.5.1
|
github.com/charmbracelet/bubbles v0.5.1
|
||||||
github.com/charmbracelet/bubbletea v0.10.3-0.20200727185851-c6a1afd3c79c
|
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/charmbracelet/glamour v0.1.1-0.20200521150359-e859bb067c06
|
||||||
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/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.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 h1:nb4KGAydLS6q3277+IqZLCGFNO2tdwrSKZ75AXAnnUI=
|
||||||
github.com/charmbracelet/bubbletea v0.10.3-0.20200727185851-c6a1afd3c79c/go.mod h1:wjGGC5pyYvpuls0so+w4Zv+aZQW7RoPvsi9UBcDlSl8=
|
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.20200807155853-9fd04eeb7cae h1:ADpWgyN9GapfrQ50tSEWty//z76XDQ8i4lhlsn0i1eY=
|
||||||
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/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 h1:FR5F7kH6i4Jm0+5ypNWWFKVcH07hIO3aGNuDXnOdWqY=
|
||||||
github.com/charmbracelet/glamour v0.1.1-0.20200521150359-e859bb067c06/go.mod h1:ECr5vYu2tKCePqAbZNUh94HiZDPMtbc9ggAy4n585JU=
|
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=
|
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 == "" {
|
if arg == "" {
|
||||||
|
|
||||||
// Read environment to get debugging stuff
|
// Read environment to get debugging stuff
|
||||||
var cfg ui.UIConfig
|
var cfg ui.Config
|
||||||
if err := babyenv.Parse(&cfg); err != nil {
|
if err := babyenv.Parse(&cfg); err != nil {
|
||||||
return fmt.Errorf("error parsing config: %v", err)
|
return fmt.Errorf("error parsing config: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Config from flags
|
||||||
|
cfg.IdentityFile = identityFile
|
||||||
|
|
||||||
// Log to file, if set
|
// Log to file, if set
|
||||||
if cfg.Logfile != "" {
|
if cfg.Logfile != "" {
|
||||||
f, err := tea.LogToFile(cfg.Logfile, "glow")
|
f, err := tea.LogToFile(cfg.Logfile, "glow")
|
||||||
|
@ -292,7 +295,7 @@ func init() {
|
||||||
|
|
||||||
// For network-related operations, namely stashing and the TUI
|
// 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().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
|
// Stash
|
||||||
stashCmd.PersistentFlags().StringVarP(&memo, "memo", "m", "", "memo/note for stashing")
|
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
|
noteCharacterLimit = 256 // should match server
|
||||||
)
|
)
|
||||||
|
|
||||||
// UIConfig contains flags for debugging the TUI.
|
// Config contains configuration specified to the TUI
|
||||||
type UIConfig struct {
|
type Config struct {
|
||||||
|
IdentityFile string
|
||||||
|
|
||||||
|
// For debugging the UI
|
||||||
Logfile string `env:"GLOW_UI_LOGFILE"`
|
Logfile string `env:"GLOW_UI_LOGFILE"`
|
||||||
HighPerformancePager bool `env:"GLOW_UI_HIGH_PERFORMANCE_PAGER" default:"true"`
|
HighPerformancePager bool `env:"GLOW_UI_HIGH_PERFORMANCE_PAGER" default:"true"`
|
||||||
GlamourEnabled bool `env:"GLOW_UI_ENABLE_GLAMOUR" default:"true"`
|
GlamourEnabled bool `env:"GLOW_UI_ENABLE_GLAMOUR" default:"true"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
config UIConfig
|
config Config
|
||||||
glowLogoTextColor = common.Color("#ECFD65")
|
glowLogoTextColor = common.Color("#ECFD65")
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewProgram returns a new Tea program
|
// NewProgram returns a new Tea program
|
||||||
func NewProgram(style string, cfg UIConfig) *tea.Program {
|
func NewProgram(style string, cfg Config) *tea.Program {
|
||||||
config = cfg
|
if cfg.Logfile != "" {
|
||||||
if config.Logfile != "" {
|
|
||||||
log.Println("-- Starting Glow ----------------")
|
log.Println("-- Starting Glow ----------------")
|
||||||
log.Printf("High performance pager: %v", cfg.HighPerformancePager)
|
log.Printf("High performance pager: %v", cfg.HighPerformancePager)
|
||||||
log.Printf("Glamour rendering: %v", cfg.GlamourEnabled)
|
log.Printf("Glamour rendering: %v", cfg.GlamourEnabled)
|
||||||
log.Println("Bubble Tea now initializing...")
|
log.Println("Bubble Tea now initializing...")
|
||||||
}
|
}
|
||||||
return tea.NewProgram(initialize(style), update, view)
|
return tea.NewProgram(initialize(cfg, style), update, view)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MESSAGES
|
// MESSAGES
|
||||||
|
@ -88,6 +90,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type model struct {
|
type model struct {
|
||||||
|
cfg Config
|
||||||
cc *charm.Client
|
cc *charm.Client
|
||||||
user *charm.User
|
user *charm.User
|
||||||
keygenState keygenState
|
keygenState keygenState
|
||||||
|
@ -124,7 +127,7 @@ func (m *model) unloadDocument() []tea.Cmd {
|
||||||
|
|
||||||
// INIT
|
// 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) {
|
return func() (tea.Model, tea.Cmd) {
|
||||||
if style == "auto" {
|
if style == "auto" {
|
||||||
dbg := te.HasDarkBackground()
|
dbg := te.HasDarkBackground()
|
||||||
|
@ -136,6 +139,7 @@ func initialize(style string) func() (tea.Model, tea.Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
m := model{
|
m := model{
|
||||||
|
cfg: cfg,
|
||||||
stash: newStashModel(),
|
stash: newStashModel(),
|
||||||
pager: newPagerModel(style),
|
pager: newPagerModel(style),
|
||||||
state: stateShowStash,
|
state: stateShowStash,
|
||||||
|
@ -144,7 +148,7 @@ func initialize(style string) func() (tea.Model, tea.Cmd) {
|
||||||
|
|
||||||
return m, tea.Batch(
|
return m, tea.Batch(
|
||||||
findLocalFiles,
|
findLocalFiles,
|
||||||
newCharmClient,
|
newCharmClient(&cfg.IdentityFile),
|
||||||
spinner.Tick(m.stash.spinner),
|
spinner.Tick(m.stash.spinner),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -279,7 +283,7 @@ func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
|
||||||
case keygenSuccessMsg:
|
case keygenSuccessMsg:
|
||||||
// The keygen's done, so let's try initializing the charm client again
|
// The keygen's done, so let's try initializing the charm client again
|
||||||
m.keygenState = keygenFinished
|
m.keygenState = keygenFinished
|
||||||
cmds = append(cmds, newCharmClient)
|
cmds = append(cmds, newCharmClient(nil))
|
||||||
|
|
||||||
case newCharmClientMsg:
|
case newCharmClientMsg:
|
||||||
m.cc = msg
|
m.cc = msg
|
||||||
|
@ -395,20 +399,26 @@ func findNextLocalFile(m model) tea.Cmd {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCharmClient() tea.Msg {
|
func newCharmClient(identityFile *string) tea.Cmd {
|
||||||
cfg, err := charm.ConfigFromEnv()
|
return func() tea.Msg {
|
||||||
if err != nil {
|
cfg, err := charm.ConfigFromEnv()
|
||||||
return errMsg(err)
|
if err != nil {
|
||||||
}
|
return errMsg(err)
|
||||||
|
}
|
||||||
|
|
||||||
cc, err := charm.NewClient(cfg)
|
if identityFile != nil {
|
||||||
if err == charm.ErrMissingSSHAuth {
|
cfg.SSHKeyPath = *identityFile
|
||||||
return sshAuthErrMsg{}
|
}
|
||||||
} else if err != nil {
|
|
||||||
return errMsg(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
func loadStash(m stashModel) tea.Cmd {
|
||||||
|
|
Loading…
Reference in a new issue