Skip to content

Commit 042c48c

Browse files
committed
feat: guide print via flag --guide/-g
1 parent c6ef3ec commit 042c48c

3 files changed

Lines changed: 55 additions & 10 deletions

File tree

cmd/root.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
/*
2-
Copyright © 2026 NAME HERE <EMAIL ADDRESS>
3-
*/
41
package cmd
52

63
import (
4+
"fmt"
75
"log"
86

97
"github.com/arfadmuzali/restui/cmd/restui"
8+
"github.com/arfadmuzali/restui/internal/help"
9+
"github.com/charmbracelet/glamour"
1010
"github.com/spf13/cobra"
1111
)
1212

1313
var Version = "dev"
1414

15+
var guide bool
16+
1517
// rootCmd represents the base command when called without any subcommands
1618
var rootCmd = &cobra.Command{
1719
Use: "restui",
1820
Version: Version,
1921
Short: "RESTUI, API Client in your terminal",
20-
// Long: `RESTUI is a Terminal User Interface API client for quickly testing
21-
// and managing HTTP requests directly from your terminal.`,
22-
// Uncomment the following line if your bare application
23-
// has an action associated with it:
2422
RunE: func(cmd *cobra.Command, args []string) error {
23+
if guide {
24+
out, err := glamour.Render(help.Guide, "dark")
25+
fmt.Print(out)
26+
return err
27+
}
2528
return restui.Execute()
2629
},
2730
}
@@ -44,5 +47,5 @@ func init() {
4447

4548
// Cobra also supports local flags, which will only run
4649
// when this action is called directly.
47-
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
50+
rootCmd.Flags().BoolVarP(&guide, "guide", "g", false, "List of shortcut and tips and trick.")
4851
}

internal/help/model.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,48 @@ type HelpModel struct {
1010
ViewportReady bool
1111
}
1212

13+
var Guide = `
14+
# Common Keybinds
15+
- **ctrl+c**: Exit
16+
- **ESC**: Close modal/popup
17+
- **alt+enter**: Send request
18+
- **F1**: Help
19+
20+
# Request Keybinds
21+
- **ctrl+l**: Go to URL
22+
- **ctrl+b**: Go to request body
23+
- **ctrl+f**: Format request body (JSON only)
24+
- **ctrl+o**: Toggle method modal/popup
25+
- **k/up**: Navigate up in method modal/popup
26+
- **j/down**: Navigate down in method modal/popup
27+
- **g**: Switch to GET method
28+
- **p**: Switch to POST method
29+
- **u**: Switch to PUT method
30+
- **a**: Switch to PATCH method
31+
- **d**: Switch to DELETE method
32+
- **ESC/enter**: Close the method modal/popup
33+
- **ctrl+h**: Go to request header
34+
- **tab**: Toggle between header key and header value
35+
- **enter**: Add header
36+
- **ctrl+k/up**: Navigate header table up
37+
- **ctrl+j/down**: Navigate header table down
38+
- **ctrl+d**: Delete header
39+
40+
# Buffer Management
41+
- **ctrl+n**: New buffer
42+
- **ctrl+x**: Delete active buffer
43+
- **ctrl+pgup**: Move to next buffer
44+
- **ctrl+pgdown**: Move to previous buffer
45+
- **ctrl+t**: Toggle buffer modal/popup
46+
- **k/up**: Navigate up in buffer modal/popup
47+
- **j/down**: Navigate down in buffer modal/popup
48+
- **ctrl+d**: Delete selected buffer
49+
- **enter**: Open selected buffer
50+
- **ESC**: Close buffer modal/popup
51+
52+
# Tips & Tricks
53+
- If you want to select and copy text, use copy-mode/selection-mode in your terminal level. For example, Kitty Terminal Emulator has ctrl+shift+h to enter copy-mode.`
54+
1355
func New() HelpModel {
1456

1557
return HelpModel{OverlayActive: false}

internal/help/update.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (m HelpModel) Update(msg tea.Msg) (HelpModel, tea.Cmd) {
2424

2525
m.ViewportReady = true
2626

27-
rawGuide := `
27+
Guide := `
2828
# Common Keybinds
2929
- **ctrl+c**: Exit
3030
- **ESC**: Close modal/popup
@@ -76,7 +76,7 @@ func (m HelpModel) Update(msg tea.Msg) (HelpModel, tea.Cmd) {
7676
return m, nil
7777
}
7878

79-
guide, err := r.Render(rawGuide)
79+
guide, err := r.Render(Guide)
8080

8181
if err != nil {
8282
m.Viewport.SetContent("Failed to render guide " + err.Error())

0 commit comments

Comments
 (0)