mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-04-28 13:48:53 +08:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
2abcd3c429
16
anko/anko.go
16
anko/anko.go
@ -48,11 +48,23 @@ func NewAnko() *Anko {
|
|||||||
return &Anko{env}
|
return &Anko{env}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define defines new symbol and value to the Anko env.
|
// DefineGlobal defines new symbol and value to the Anko env.
|
||||||
func (a *Anko) Define(symbol string, value interface{}) error {
|
func (a *Anko) DefineGlobal(symbol string, value interface{}) error {
|
||||||
return a.env.DefineGlobal(symbol, value)
|
return a.env.DefineGlobal(symbol, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Anko) NewModule(name string) (*Anko, error) {
|
||||||
|
env, err := a.env.NewModule(name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &Anko{env}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Anko) Define(name string, value interface{}) error {
|
||||||
|
return a.env.Define(name, value)
|
||||||
|
}
|
||||||
|
|
||||||
// Set sets new value to existing symbol. Use this when change value under an
|
// Set sets new value to existing symbol. Use this when change value under an
|
||||||
// existing symbol.
|
// existing symbol.
|
||||||
func (a *Anko) Set(symbol string, value interface{}) error {
|
func (a *Anko) Set(symbol string, value interface{}) error {
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
func TestDefine(t *testing.T) {
|
func TestDefine(t *testing.T) {
|
||||||
a := NewAnko()
|
a := NewAnko()
|
||||||
err := a.Define("x", 12)
|
err := a.DefineGlobal("x", 12)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
@ -18,7 +18,7 @@ func TestDefine(t *testing.T) {
|
|||||||
|
|
||||||
func TestSet(t *testing.T) {
|
func TestSet(t *testing.T) {
|
||||||
a := NewAnko()
|
a := NewAnko()
|
||||||
err := a.Define("x", 12)
|
err := a.DefineGlobal("x", 12)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ func TestGet(t *testing.T) {
|
|||||||
a := NewAnko()
|
a := NewAnko()
|
||||||
|
|
||||||
expect := 12
|
expect := 12
|
||||||
err := a.Define("x", expect)
|
err := a.DefineGlobal("x", expect)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ func TestGetInt(t *testing.T) {
|
|||||||
got = a.GetInt("S.y")
|
got = a.GetInt("S.y")
|
||||||
assert.Equal(t, 0, got)
|
assert.Equal(t, 0, got)
|
||||||
|
|
||||||
a.Define("z", expect)
|
a.DefineGlobal("z", expect)
|
||||||
val := a.GetInt("z")
|
val := a.GetInt("z")
|
||||||
|
|
||||||
assert.Equal(t, expect, val)
|
assert.Equal(t, expect, val)
|
||||||
@ -102,7 +102,7 @@ func TestGetString(t *testing.T) {
|
|||||||
got = a.GetString("S.y")
|
got = a.GetString("S.y")
|
||||||
assert.Equal(t, "", got)
|
assert.Equal(t, "", got)
|
||||||
|
|
||||||
a.Define("z", expect)
|
a.DefineGlobal("z", expect)
|
||||||
val := a.GetString("z")
|
val := a.GetString("z")
|
||||||
|
|
||||||
assert.Equal(t, expect, val)
|
assert.Equal(t, expect, val)
|
||||||
@ -111,7 +111,7 @@ func TestGetString(t *testing.T) {
|
|||||||
func TestGetBool(t *testing.T) {
|
func TestGetBool(t *testing.T) {
|
||||||
expect := true
|
expect := true
|
||||||
a := NewAnko()
|
a := NewAnko()
|
||||||
a.Define("x", expect)
|
a.DefineGlobal("x", expect)
|
||||||
|
|
||||||
_, err := a.Execute(`module S { x = true }`)
|
_, err := a.Execute(`module S { x = true }`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -452,7 +452,7 @@ func (c Command) defineCommands() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
for name, cmd := range c.commands {
|
for name, cmd := range c.commands {
|
||||||
err := gomu.anko.Define(name, cmd)
|
err := gomu.anko.DefineGlobal(name, cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logError(err)
|
logError(err)
|
||||||
}
|
}
|
||||||
|
27
playlist.go
27
playlist.go
@ -22,8 +22,11 @@ import (
|
|||||||
"github.com/ztrue/tracerr"
|
"github.com/ztrue/tracerr"
|
||||||
|
|
||||||
"github.com/issadarkthing/gomu/lyric"
|
"github.com/issadarkthing/gomu/lyric"
|
||||||
|
"github.com/issadarkthing/gomu/player"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ player.Audio = (*AudioFile)(nil)
|
||||||
|
|
||||||
// AudioFile represents directories and mp3 files
|
// AudioFile represents directories and mp3 files
|
||||||
// isAudioFile equals to false if it is a directory
|
// isAudioFile equals to false if it is a directory
|
||||||
type AudioFile struct {
|
type AudioFile struct {
|
||||||
@ -43,6 +46,29 @@ func (a *AudioFile) Path() string {
|
|||||||
return a.path
|
return a.path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *AudioFile) IsAudioFile() bool {
|
||||||
|
return a.isAudioFile
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AudioFile) Len() time.Duration {
|
||||||
|
return a.length
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AudioFile) GetParent() *AudioFile {
|
||||||
|
if a.parent == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return a.parent.GetReference().(*AudioFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AudioFile) String() string {
|
||||||
|
if a == nil {
|
||||||
|
return "nil"
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%#v", a)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Playlist struct represents playlist panel
|
// Playlist struct represents playlist panel
|
||||||
// that shows the tree of the music directory
|
// that shows the tree of the music directory
|
||||||
type Playlist struct {
|
type Playlist struct {
|
||||||
@ -206,7 +232,6 @@ func newPlaylist(args Args) *Playlist {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return playlist
|
return playlist
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the current file highlighted in the playlist
|
// Returns the current file highlighted in the playlist
|
||||||
|
10
popup.go
10
popup.go
@ -601,10 +601,11 @@ func infoPopup(message string) {
|
|||||||
defaultTimedPopup(" Info ", message)
|
defaultTimedPopup(" Info ", message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func inputPopup(prompt string, handler func(string)) {
|
func inputPopup(prompt, placeholder string, handler func(string)) {
|
||||||
|
|
||||||
popupID := "general-input-popup"
|
popupID := "general-input-popup"
|
||||||
input := newInputPopup(popupID, "", prompt+": ", "")
|
input := newInputPopup(popupID, "", prompt+": ", "")
|
||||||
|
input.SetText(placeholder)
|
||||||
input.SetInputCapture(func(e *tcell.EventKey) *tcell.EventKey {
|
input.SetInputCapture(func(e *tcell.EventKey) *tcell.EventKey {
|
||||||
|
|
||||||
switch e.Key() {
|
switch e.Key() {
|
||||||
@ -640,16 +641,17 @@ func replPopup() {
|
|||||||
history := []string{}
|
history := []string{}
|
||||||
upCount := 0
|
upCount := 0
|
||||||
|
|
||||||
gomu.anko.Define("println", func(x ...interface{}) {
|
gomu.anko.DefineGlobal("println", func(x ...interface{}) {
|
||||||
fmt.Fprintln(textview, x...)
|
fmt.Fprintln(textview, x...)
|
||||||
})
|
})
|
||||||
gomu.anko.Define("print", func(x ...interface{}) {
|
gomu.anko.DefineGlobal("print", func(x ...interface{}) {
|
||||||
fmt.Fprint(textview, x...)
|
fmt.Fprint(textview, x...)
|
||||||
})
|
})
|
||||||
gomu.anko.Define("printf", func(format string, x ...interface{}) {
|
gomu.anko.DefineGlobal("printf", func(format string, x ...interface{}) {
|
||||||
fmt.Fprintf(textview, format, x...)
|
fmt.Fprintf(textview, format, x...)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
input.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
input.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
||||||
|
|
||||||
switch event.Key() {
|
switch event.Key() {
|
||||||
|
1
queue.go
1
queue.go
@ -414,7 +414,6 @@ func newQueue() *Queue {
|
|||||||
SetBackgroundColor(gomu.colors.background)
|
SetBackgroundColor(gomu.colors.background)
|
||||||
|
|
||||||
return queue
|
return queue
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert string to sha1.
|
// Convert string to sha1.
|
||||||
|
31
start.go
31
start.go
@ -58,12 +58,30 @@ func getArgs() Args {
|
|||||||
|
|
||||||
// built-in functions
|
// built-in functions
|
||||||
func defineBuiltins() {
|
func defineBuiltins() {
|
||||||
gomu.anko.Define("debug_popup", debugPopup)
|
gomu.anko.DefineGlobal("debug_popup", debugPopup)
|
||||||
gomu.anko.Define("info_popup", infoPopup)
|
gomu.anko.DefineGlobal("info_popup", infoPopup)
|
||||||
gomu.anko.Define("input_popup", inputPopup)
|
gomu.anko.DefineGlobal("input_popup", inputPopup)
|
||||||
gomu.anko.Define("show_popup", defaultTimedPopup)
|
gomu.anko.DefineGlobal("show_popup", defaultTimedPopup)
|
||||||
gomu.anko.Define("search_popup", searchPopup)
|
gomu.anko.DefineGlobal("search_popup", searchPopup)
|
||||||
gomu.anko.Define("shell", shell)
|
gomu.anko.DefineGlobal("shell", shell)
|
||||||
|
}
|
||||||
|
|
||||||
|
func defineInternals() {
|
||||||
|
playlist, _ := gomu.anko.NewModule("Playlist")
|
||||||
|
playlist.Define("get_focused", gomu.playlist.getCurrentFile)
|
||||||
|
|
||||||
|
queue, _ := gomu.anko.NewModule("Queue")
|
||||||
|
queue.Define("get_focused", func() *AudioFile {
|
||||||
|
index := gomu.queue.GetCurrentItem()
|
||||||
|
if index < 0 || index > len(gomu.queue.items)-1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
item := gomu.queue.items[index]
|
||||||
|
return item
|
||||||
|
})
|
||||||
|
|
||||||
|
player, _ := gomu.anko.NewModule("Player")
|
||||||
|
player.Define("current_audio", gomu.player.GetCurrentSong)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupHooks(hook *hook.EventHook, anko *anko.Anko) {
|
func setupHooks(hook *hook.EventHook, anko *anko.Anko) {
|
||||||
@ -326,6 +344,7 @@ func start(application *tview.Application, args Args) {
|
|||||||
tview.Styles.PrimitiveBackgroundColor = gomu.colors.popup
|
tview.Styles.PrimitiveBackgroundColor = gomu.colors.popup
|
||||||
|
|
||||||
gomu.initPanels(application, args)
|
gomu.initPanels(application, args)
|
||||||
|
defineInternals()
|
||||||
|
|
||||||
gomu.player.SetSongStart(func(audio player.Audio) {
|
gomu.player.SetSongStart(func(audio player.Audio) {
|
||||||
|
|
||||||
|
16
test/config
16
test/config
@ -122,6 +122,22 @@ Keybinds.def_q("i", func() {
|
|||||||
|
|
||||||
Keybinds.def_g("c", show_colors)
|
Keybinds.def_g("c", show_colors)
|
||||||
|
|
||||||
|
# better rename command which does not change the mtime of file
|
||||||
|
Keybinds.def_g("R", func() {
|
||||||
|
exec = import("os/exec")
|
||||||
|
os = import("os")
|
||||||
|
|
||||||
|
file = Playlist.get_focused()
|
||||||
|
dir = file.GetParent().Path()
|
||||||
|
|
||||||
|
input_popup("New name", file.Name(), func(new_name) {
|
||||||
|
cmd = exec.Command("cp", "-p", file.Path(), dir + "/" + new_name)
|
||||||
|
cmd.Run()
|
||||||
|
os.Remove(file.Path())
|
||||||
|
refresh()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
# you can get the syntax highlighting for this language here:
|
# you can get the syntax highlighting for this language here:
|
||||||
# https://github.com/mattn/anko/tree/master/misc/vim
|
# https://github.com/mattn/anko/tree/master/misc/vim
|
||||||
# vim: ft=anko
|
# vim: ft=anko
|
||||||
|
Loading…
x
Reference in New Issue
Block a user