Browse Source

Start #28: Implements optional stubs for new entry

v0.6.0-dev
bacardi55 10 months ago
parent
commit
2ad10f4ebd
  1. 4
      Makefile
  2. 3
      README.md
  3. 2
      config/config.go
  4. 25
      core/structs.go
  5. 2
      go.mod
  6. 21
      ui/tltui.go
  7. 5
      ui/tui.go

4
Makefile

@ -1,7 +1,7 @@
GOCMD := CGO_ENABLED=0 go
BINARY := gtl
BINDIR := ./bin
VERSION := 0.5.2
VERSION := 0.6.0
GOLDFLAGS := -s -w -X main.Version=$(VERSION)
@ -37,4 +37,4 @@ dependencies:
${GOCMD} get "code.rocketnine.space/tslocum/cview"
${GOCMD} get "github.com/gdamore/tcell"
${GOCMD} get "code.rocketnine.space/tslocum/cbind"
${GOCMD} get "github.com/atotto/clipboard/cmd/gocopy"
${GOCMD} get "github.com/atotto/clipboard/"

3
README.md

@ -180,6 +180,9 @@ post_edit_refresh = false
# Indicate 0 for all entries.
# Settings available since v0.6.0
tui_max_entries = 0
# Copy a pre formatted text to clipboard when creating a new entry
# Settings available since v0.6.0
tui_copy_stub_clipboard = false
```
By default, gtl will look for ~/.config/gtl/gtl.toml . It will create it if needed.

2
config/config.go

@ -55,6 +55,8 @@ post_edit_refresh = false
# Limit the number of entries displayed in TUI.
# Indicate 0 for all entries.
tui_max_entries = 0
# Copy a pre formatted text to clipboard when creating a new entry
tui_copy_stub_clipboard = false
`)
func Init(configArg string, Data *core.TlData) {

25
core/structs.go

@ -28,18 +28,19 @@ func (Data *TlData) RefreshFeeds() error {
}
type TlConfig struct {
Subscribed_data string
Date_format string
Log_file string
Highlights string
Cli_limit int
Mode string
Tui_status_emoji bool
Allow_edit bool
Tinylog_path string
Post_edit_script string
Post_edit_refresh bool
Tui_max_entries int
Subscribed_data string
Date_format string
Log_file string
Highlights string
Cli_limit int
Mode string
Tui_status_emoji bool
Allow_edit bool
Tinylog_path string
Post_edit_script string
Post_edit_refresh bool
Tui_max_entries int
Tui_copy_stub_clipboard bool
}
type TlFeed struct {

2
go.mod

@ -6,7 +6,7 @@ require (
code.rocketnine.space/tslocum/cbind v0.1.5
code.rocketnine.space/tslocum/cview v1.5.6
git.sr.ht/~adnano/go-gemini v0.2.1
github.com/atotto/clipboard v0.1.4 // indirect
github.com/atotto/clipboard v0.1.4
github.com/fatih/color v1.12.0
github.com/gdamore/tcell/v2 v2.3.11
github.com/mitchellh/go-homedir v1.1.0

21
ui/tltui.go

@ -8,8 +8,8 @@ import (
"code.rocketnine.space/tslocum/cbind"
"code.rocketnine.space/tslocum/cview"
"github.com/atotto/clipboard"
"github.com/gdamore/tcell/v2"
//"github.com/atotto/clipboard"
"git.bacardi55.io/bacardi55/gtl/core"
)
@ -24,6 +24,11 @@ type TlTuiSubs struct {
Items []core.TlFeed
}
type TlClipboard struct {
Enabled bool
DateFormat string
}
type TlTUI struct {
App *cview.Application
Layout *cview.Flex
@ -44,6 +49,7 @@ type TlTUI struct {
Help bool
DisplaySidebar bool
Emoji bool
Clipboard TlClipboard
Muted []string
NbEntries int
SelectedEntry int
@ -67,6 +73,10 @@ func (TlTui *TlTUI) InitApp(useEmoji bool) {
if useEmoji == true {
TlTui.Emoji = true
}
TlTui.Clipboard = TlClipboard{
Enabled: false,
}
}
func (TlTui *TlTUI) SetAppUI(data *core.TlData) {
@ -95,6 +105,11 @@ func (TlTui *TlTUI) SetAppUI(data *core.TlData) {
TlTui.RefreshBox = createRefreshBox()
TlTui.NbEntries = len(data.Stream.Items)
if data.Config.Tui_copy_stub_clipboard == true {
TlTui.Clipboard.Enabled = true
TlTui.Clipboard.DateFormat = data.Config.Date_format
}
}
func (TlTui *TlTUI) InitTlEditor(tinylogPath string, postScriptPath string, postScriptRefresh bool) error {
@ -194,6 +209,10 @@ func (TlTui *TlTUI) SetShortcuts() {
handleNewEntry := func(ev *tcell.EventKey) *tcell.EventKey {
mainButtonName, buttonName, message, execFunc := "Cancel", "", "", func() {}
if TlTui.Clipboard.Enabled == true {
clipboard.WriteAll(createNewEntryStub(TlTui.Clipboard.DateFormat))
}
if TlTui.App.Suspend(editTl) == true {
message = "Tinylog edited successfully"

5
ui/tui.go

@ -506,3 +506,8 @@ func openEntryModal() {
//TODO.
}
*/
func createNewEntryStub(dateFormat string) string {
stub := "## " + time.Now().Format(dateFormat) + "\n"
return stub
}

Loading…
Cancel
Save