refactor: rename s to content

This commit is contained in:
Andrey Nering 2025-02-13 13:58:14 -03:00
commit 7fbc040cc8
2 changed files with 11 additions and 13 deletions

12
main.go
View file

@ -293,13 +293,13 @@ func executeCLI(cmd *cobra.Command, src *source, w io.Writer) error {
return err
}
s := string(b)
content := string(b)
ext := filepath.Ext(src.URL)
if isCode {
s = utils.WrapCodeBlock(string(b), ext)
content = utils.WrapCodeBlock(string(b), ext)
}
out, err := r.Render(s)
out, err := r.Render(content)
if err != nil {
return err
}
@ -318,14 +318,14 @@ func executeCLI(cmd *cobra.Command, src *source, w io.Writer) error {
c.Stdout = os.Stdout
return c.Run()
case tui || cmd.Flags().Changed("tui"):
return runTUI(src.URL, s)
return runTUI(src.URL, content)
default:
_, err = fmt.Fprint(w, out)
return err
}
}
func runTUI(path string, s string) error {
func runTUI(path string, content string) error {
// Read environment to get debugging stuff
cfg, err := env.ParseAs[ui.Config]()
if err != nil {
@ -345,7 +345,7 @@ func runTUI(path string, s string) error {
cfg.PreserveNewLines = preserveNewLines
// Run Bubble Tea program
if _, err := ui.NewProgram(cfg, s).Run(); err != nil {
if _, err := ui.NewProgram(cfg, content).Run(); err != nil {
return err
}

View file

@ -29,7 +29,7 @@ var (
)
// NewProgram returns a new Tea program.
func NewProgram(cfg Config, s string) *tea.Program {
func NewProgram(cfg Config, content string) *tea.Program {
log.Debug(
"Starting glow",
"high_perf_pager",
@ -43,7 +43,7 @@ func NewProgram(cfg Config, s string) *tea.Program {
if cfg.EnableMouse {
opts = append(opts, tea.WithMouseCellMotion())
}
m := newModel(cfg, s)
m := newModel(cfg, content)
return tea.NewProgram(m, opts...)
}
@ -129,7 +129,7 @@ func (m *model) unloadDocument() []tea.Cmd {
return batch
}
func newModel(cfg Config, s string) tea.Model {
func newModel(cfg Config, content string) tea.Model {
initSections()
if cfg.GlamourStyle == styles.AutoStyle {
@ -152,11 +152,9 @@ func newModel(cfg Config, s string) tea.Model {
}
path := cfg.Path
if path == "" && s != "" {
if path == "" && content != "" {
m.state = stateShowDocument
m.pager.currentDocument = markdown{
Body: s,
}
m.pager.currentDocument = markdown{Body: content}
return m
}