Skip to content

fix: disallow 'h' key when was pipeline #687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
ruleguard:
uses: charmbracelet/meta/.github/workflows/ruleguard.yml@main
with:
go-version: stable
go-version: 1.23.6
13 changes: 1 addition & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,10 @@ func validateOptions(cmd *cobra.Command) error {
return nil
}

func stdinIsPipe() (bool, error) {
stat, err := os.Stdin.Stat()
if err != nil {
return false, err
}
if stat.Mode()&os.ModeCharDevice == 0 || stat.Size() > 0 {
return true, nil
}
return false, nil
}

func execute(cmd *cobra.Command, args []string) error {
// if stdin is a pipe then use stdin for input. note that you can also
// explicitly use a - to read from stdin.
if yes, err := stdinIsPipe(); err != nil {
if yes, err := utils.StdinIsPipe(); err != nil {
return err
} else if yes {
src := &source{reader: os.Stdin}
Expand Down
12 changes: 11 additions & 1 deletion ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,17 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Quit

case "left", "h", "delete":
if m.state == stateShowDocument {
isPipe, _ := utils.StdinIsPipe()
path := m.common.cfg.Path
if path == "" {
path = "."
}
isDir := false
info, err := os.Stat(path)
if err == nil && info.IsDir() {
isDir = true
}
if m.state == stateShowDocument && !isPipe && isDir {
cmds = append(cmds, m.unloadDocument()...)
return m, tea.Batch(cmds...)
}
Expand Down
11 changes: 11 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,14 @@ func GlamourStyle(style string, isCode bool) glamour.TermRendererOption {

return glamour.WithStyles(styleConfig)
}

func StdinIsPipe() (bool, error) {
stat, err := os.Stdin.Stat()
if err != nil {
return false, err
}
if stat.Mode()&os.ModeCharDevice == 0 || stat.Size() > 0 {
return true, nil
}
return false, nil
}
Loading