-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: toggle file picker, scroll textarea
- Loading branch information
Showing
7 changed files
with
432 additions
and
995 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/charmbracelet/bubbles/key" | ||
) | ||
|
||
type keymap = struct { | ||
file, quit key.Binding | ||
} | ||
|
||
func newkeymap() keymap { | ||
return keymap{ | ||
file: key.NewBinding( | ||
key.WithKeys("f", "F"), | ||
key.WithHelp("f", "toggle file picker"), | ||
), | ||
quit: key.NewBinding( | ||
key.WithKeys("esc", "q"), | ||
key.WithHelp("q", "quit"), | ||
), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"os" | ||
"text/template" | ||
|
||
"github.com/Masterminds/sprig/v3" | ||
) | ||
|
||
func loadTmplData() map[string]any { | ||
ret := map[string]any{} | ||
data, err := os.ReadFile("data.json") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
err = json.Unmarshal(data, &ret) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
return ret | ||
} | ||
|
||
// loadFile reads the file and attempt to render it as a template, returns | ||
// the original file, the rendered. In case of errors the returned value | ||
// will contain the error text. | ||
func loadFile(fpath string, tdata map[string]any) (string, string) { | ||
fdata, err := os.ReadFile(fpath) | ||
if err != nil { | ||
return fmt.Sprintf("error reading file %s: %+v\n", fpath, err), "" | ||
} | ||
t := template.New(fpath).Option("missingkey=zero").Funcs(sprig.FuncMap()) | ||
|
||
setDelimiters(t, tdata) | ||
|
||
fstring := string(fdata) | ||
t, err = t.Parse(fstring) | ||
if err != nil { | ||
return fstring, fmt.Sprintf("error parsing template %s: %+v\n", fpath, err) | ||
} | ||
|
||
var buff bytes.Buffer | ||
err = t.Execute(&buff, tdata) | ||
if err != nil { | ||
return fstring, fmt.Sprintf("error rendering template %s: %+v\n", fpath, err) | ||
} | ||
|
||
return fstring, buff.String() | ||
} | ||
|
||
const ( | ||
leftDelim = "left_delimiter" | ||
rightDelim = "right_delimiter" | ||
) | ||
|
||
// finds and sets the delimiters | ||
func setDelimiters(t *template.Template, tdata map[string]any) { | ||
// default delimiters, left and right | ||
var ld, rd = "{{", "}}" | ||
if left, ok := tdata[leftDelim]; ok { | ||
ld = left.(string) | ||
} | ||
if right, ok := tdata[rightDelim]; ok { | ||
rd = right.(string) | ||
} | ||
t.Delims(ld, rd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import "github.com/charmbracelet/lipgloss" | ||
|
||
var ( | ||
cursorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("212")) | ||
|
||
cursorLineStyle = lipgloss.NewStyle(). | ||
Background(lipgloss.Color("57")). | ||
Foreground(lipgloss.Color("230")) | ||
|
||
placeholderStyle = lipgloss.NewStyle(). | ||
Foreground(lipgloss.Color("238")) | ||
|
||
endOfBufferStyle = lipgloss.NewStyle(). | ||
Foreground(lipgloss.Color("235")) | ||
|
||
focusedPlaceholderStyle = lipgloss.NewStyle(). | ||
Foreground(lipgloss.Color("99")) | ||
|
||
focusedBorderStyle = lipgloss.NewStyle(). | ||
Border(lipgloss.RoundedBorder()). | ||
BorderForeground(lipgloss.Color("238")) | ||
|
||
blurredBorderStyle = lipgloss.NewStyle(). | ||
Border(lipgloss.HiddenBorder()) | ||
) |
Oops, something went wrong.