-
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.
- Loading branch information
Showing
11 changed files
with
214 additions
and
41 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
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
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,68 @@ | ||
package dialog | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"strings" | ||
|
||
"github.com/charmbracelet/bubbles/list" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/charmbracelet/lipgloss" | ||
"github.com/shalldie/gog/gs" | ||
) | ||
|
||
// https://github.com/charmbracelet/bubbletea/blob/master/examples/list-simple/main.go | ||
|
||
var ( | ||
itemStyle = lipgloss.NewStyle().PaddingLeft(4) | ||
selectedItemStyle = lipgloss.NewStyle().PaddingLeft(2).Foreground(lipgloss.Color("170")) | ||
) | ||
|
||
type selectItem string | ||
|
||
func (i selectItem) FilterValue() string { return "" } | ||
|
||
type itemDelegate struct{} | ||
|
||
func (d itemDelegate) Height() int { return 1 } | ||
func (d itemDelegate) Spacing() int { return 0 } | ||
func (d itemDelegate) Update(_ tea.Msg, _ *list.Model) tea.Cmd { return nil } | ||
func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) { | ||
i, ok := listItem.(selectItem) | ||
if !ok { | ||
return | ||
} | ||
|
||
str := fmt.Sprintf("%d. %s", index+1, i) | ||
|
||
fn := itemStyle.Render | ||
if index == m.Index() { | ||
fn = func(s ...string) string { | ||
return selectedItemStyle.Render("> " + strings.Join(s, " ")) | ||
} | ||
} | ||
|
||
fmt.Fprint(w, fn(str)) | ||
} | ||
|
||
func createSelect() list.Model { | ||
l := list.New([]list.Item{}, itemDelegate{}, 0, 0) | ||
l.SetShowTitle(false) | ||
l.SetFilteringEnabled(false) | ||
l.SetShowPagination(false) | ||
l.SetShowHelp(false) | ||
l.SetShowStatusBar(false) | ||
return l | ||
} | ||
|
||
func (m *DialogModel) updateSelect() { | ||
if len(m.Payload.SelectList) <= 0 { | ||
return | ||
} | ||
items := gs.Map(m.Payload.SelectList, func(pf string, index int) list.Item { | ||
return selectItem(pf) | ||
}) | ||
|
||
m.Select.SetItems(items) | ||
m.Select.SetHeight(len(items) + 3) | ||
} |
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,43 @@ | ||
package status_bar | ||
|
||
import ( | ||
"github.com/shalldie/tnote/internal/app/pkgs/dialog" | ||
"github.com/shalldie/tnote/internal/app/store" | ||
"github.com/shalldie/tnote/internal/conf" | ||
) | ||
|
||
// zone | ||
var PLATFORM_ID = "STATUSBAR_SHOW_PLATFORM" | ||
|
||
// 展示 「平台」弹框 | ||
func (m *StatusBarModel) showPlatform() { | ||
|
||
store.Send(dialog.DialogPayload{ | ||
Mode: dialog.ModeAlert, | ||
Title: "平台", | ||
Message: "选择要使用的平台\n", | ||
SelectList: []string{conf.PF_GITHUB, conf.PF_GITEE}, | ||
Width: 50, | ||
FnOK: func(args ...string) bool { | ||
if args[0] == conf.PF_GITHUB && !conf.HasGithub() { | ||
go store.Send(store.StatusPayload{ | ||
Message: "", | ||
Duration: 3, | ||
}) | ||
return false | ||
} | ||
|
||
if args[0] == conf.PF_GITEE && !conf.HasGitee() { | ||
go store.Send(store.StatusPayload{ | ||
Message: "", | ||
Duration: 3, | ||
}) | ||
return false | ||
} | ||
|
||
conf.PF_CURRENT = args[0] | ||
go store.Setup() | ||
return true | ||
}, | ||
}) | ||
} |
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 |
---|---|---|
|
@@ -13,3 +13,6 @@ type CMD_SELECT_FILE string | |
|
||
// 触发编辑模式 | ||
type CMD_INVOKE_EDIT bool | ||
|
||
// 展示平台选择 | ||
type CMD_SHOW_PLATFORM bool |
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.