Skip to content

Commit 7a0b528

Browse files
committed
Drop shell functionality but keep live shell
1 parent b77def8 commit 7a0b528

4 files changed

Lines changed: 2 additions & 559 deletions

File tree

README.md

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
## Introduction
88

9-
balafon is a multitrack MIDI sequencer language and interpreter. It consists of a shell with live mode, player and a linter.
9+
balafon is a multitrack MIDI sequencer language and interpreter. It consists of a live shell, player and a linter.
1010

1111
## Install
1212

@@ -46,27 +46,7 @@ cat examples/bach | balafon play --port "VMPK" -
4646
balafon play --port 2 examples/bonham
4747
```
4848

49-
- Enter a shell on the default port:
50-
51-
```sh
52-
balafon shell
53-
```
54-
55-
A shell is a text shell for the balafon language. It is capable of multiline input when entering bars.
56-
57-
- Enter a shell on a specific port:
58-
59-
```sh
60-
balafon shell --port "Hydrogen"
61-
```
62-
63-
- Load a file and enter a shell:
64-
65-
```sh
66-
balafon load --port "Hydrogen" examples/bonham
67-
```
68-
69-
- Enter live mode by entering the `live` command:
49+
- Enter live mode:
7050

7151
```sh
7252
balafon live --port "Hydrogen" examples/live_drumset
@@ -96,9 +76,7 @@ Available Commands:
9676
help Help about any command
9777
lint Lint a file
9878
live Load a file and continue in a live shell
99-
load Load a file and continue in a balafon shell
10079
play Play a file
101-
shell Run a balafon shell
10280

10381
Flags:
10482
-h, --help help for this command

cmd/balafon/main.go

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"os"
99
"strconv"
1010

11-
"github.com/c-bata/go-prompt"
1211
"github.com/mgnsk/balafon/interpreter"
1312
"github.com/mgnsk/balafon/lint"
1413
"github.com/mgnsk/balafon/player"
@@ -50,8 +49,6 @@ func main() {
5049
},
5150
}
5251

53-
root.AddCommand(createCmdShell())
54-
root.AddCommand(createCmdLoad())
5552
root.AddCommand(createCmdLive())
5653
root.AddCommand(createCmdPlay())
5754
root.AddCommand(createCmdLint())
@@ -61,66 +58,6 @@ func main() {
6158
}
6259
}
6360

64-
func createCmdShell() *cobra.Command {
65-
cmd := &cobra.Command{
66-
Use: "shell",
67-
Short: "Run a balafon shell",
68-
SilenceErrors: true,
69-
SilenceUsage: true,
70-
RunE: func(c *cobra.Command, _ []string) error {
71-
out, err := openOut(c.Flag("port").Value.String())
72-
if err != nil {
73-
return err
74-
}
75-
76-
it := interpreter.New()
77-
seq := sequencer.New()
78-
runPrompt(out, it, seq)
79-
80-
return nil
81-
},
82-
}
83-
addPortFlag(cmd)
84-
return cmd
85-
}
86-
87-
func createCmdLoad() *cobra.Command {
88-
cmd := &cobra.Command{
89-
Use: "load [file]",
90-
Short: "Load a file and continue in a balafon shell",
91-
Args: cobra.ExactArgs(1),
92-
RunE: func(c *cobra.Command, args []string) error {
93-
file, err := ioutil.ReadFile(args[0])
94-
if err != nil {
95-
return err
96-
}
97-
98-
out, err := openOut(c.Flag("port").Value.String())
99-
if err != nil {
100-
return err
101-
}
102-
103-
it := interpreter.New()
104-
seq := sequencer.New()
105-
106-
if err := it.Eval(file); err != nil {
107-
return err
108-
}
109-
110-
fmt.Println(string(file))
111-
112-
seq.AddBars(it.Flush()...)
113-
seq.Flush()
114-
115-
runPrompt(out, it, seq)
116-
117-
return nil
118-
},
119-
}
120-
addPortFlag(cmd)
121-
return cmd
122-
}
123-
12461
func createCmdLive() *cobra.Command {
12562
cmd := &cobra.Command{
12663
Use: "live [file]",
@@ -226,40 +163,6 @@ func createCmdLint() *cobra.Command {
226163
return cmd
227164
}
228165

229-
func runPrompt(out drivers.Out, it *interpreter.Interpreter, seq *sequencer.Sequencer) {
230-
p := player.New(out)
231-
232-
pt := shell.NewBufferedPrompt(
233-
prompt.NewStandardInputParser(),
234-
prompt.NewStdoutWriter(),
235-
func(in string) {
236-
if err := it.EvalString(in); err != nil {
237-
// Keep old input
238-
fmt.Println(err)
239-
return
240-
}
241-
242-
seq.AddBars(it.Flush()...)
243-
244-
events := seq.Flush()
245-
246-
if err := p.Play(events...); err != nil {
247-
fmt.Println(err)
248-
}
249-
250-
return
251-
},
252-
func(in prompt.Document) []prompt.Suggest {
253-
// TODO: fix tab key overwrites existing text
254-
return it.Suggest(in)
255-
},
256-
nil,
257-
)
258-
259-
defer shell.RestoreTerminal()
260-
pt.Run()
261-
}
262-
263166
func openInputFile(name string) (io.ReadCloser, error) {
264167
if name == "-" {
265168
return os.Stdin, nil

0 commit comments

Comments
 (0)