Skip to content

Commit

Permalink
mosaic: new multiplexer
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed Jul 11, 2024
1 parent 960cd93 commit 752ca08
Show file tree
Hide file tree
Showing 36 changed files with 3,704 additions and 520 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Pulumi.yaml
# Local Netlify folder
.netlify
.env
tmp
19 changes: 19 additions & 0 deletions cmd/multiplexer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import (
"context"
"time"

"github.com/sst/ion/cmd/sst/mosaic/multiplexer2/switcher"
)

func main() {
// make raw
ctx := context.Background()
s := switcher.New(ctx)
s.AddProcess("1", []string{"/home/thdxr/dev/projects/sst/ion/dist/sst", "dev"}, "sst", "", false)
s.AddProcess("2", []string{"zsh"}, "shell", "", true)
s.AddProcess("3", []string{"ping", "google.com"}, "ping", "", true)
time.Sleep(time.Second * 10)
s.Shutdown()
}
1 change: 1 addition & 0 deletions cmd/sst/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func CmdDev(cli *cli.Cli) error {
}
}()

slog.Info("starting server")
state := &server.State{}
silent := cli.Bool("silent")
u := ui.New(cli.Context, ui.ProgressModeDev, func(o *ui.Options) {
Expand Down
2 changes: 2 additions & 0 deletions cmd/sst/mosaic/deploy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mosaic

import (
"log/slog"
"os"

"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
Expand Down Expand Up @@ -37,6 +38,7 @@ func CmdMosaicDeploy(c *cli.Cli) error {
}

u := ui.New(c.Context, ui.ProgressModeDev)
slog.Info("initialized ui")
u.Header("dev", "app", "foo")
for {
select {
Expand Down
24 changes: 14 additions & 10 deletions cmd/sst/mosaic/mosaic.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/sst/ion/cmd/sst/mosaic/aws"
"github.com/sst/ion/cmd/sst/mosaic/bus"
"github.com/sst/ion/cmd/sst/mosaic/deployer"
"github.com/sst/ion/cmd/sst/mosaic/multiplexer"
"github.com/sst/ion/cmd/sst/mosaic/multiplexer2/switcher"
"github.com/sst/ion/cmd/sst/mosaic/server"
"github.com/sst/ion/cmd/sst/mosaic/watcher"
"github.com/sst/ion/pkg/project"
Expand Down Expand Up @@ -42,6 +42,7 @@ func CmdMosaic(c *cli.Cli) error {
for {
select {
case <-c.Context.Done():
fmt.Println("")
return nil
case _, ok := <-evts:
if !ok {
Expand Down Expand Up @@ -112,18 +113,18 @@ func CmdMosaic(c *cli.Cli) error {
})

currentExecutable, _ := os.Executable()
multi, err := multiplexer.New()
sw := switcher.NewSidebar(c.Context)
// multi, err := multiplexer.New()
multiEnv := []string{
fmt.Sprintf("SST_SERVER=http://localhost:%v", server.Port),
"SST_STAGE=" + p.App().Stage,
}
multi.AddPane("deploy", []string{currentExecutable, "mosaic-deploy"}, "⑆ SST", "", false, multiEnv...)
// multi.AddPane("shell", []string{currentExecutable, "shell"}, "Shell", "", true, multiEnv...)

wg.Go(func() error {
sw.AddProcess("deploy", []string{currentExecutable, "mosaic-deploy"}, "⑆ SST", "", false, multiEnv...)
// sw.AddProcess("shell", []string{currentExecutable, "shell"}, "Shell", "", true, multiEnv...)
go func() {
defer c.Cancel()
return multi.Start()
})
sw.Start()
}()

wg.Go(func() error {
evts := bus.Subscribe(&project.CompleteEvent{})
Expand All @@ -141,7 +142,7 @@ func CmdMosaic(c *cli.Cli) error {
}
dir := filepath.Join(cwd, d.Directory)
slog.Info("mosaic", "dev", d.Name, "directory", dir)
multi.AddPane(
sw.AddProcess(
d.Name,
append([]string{currentExecutable, "mosaic", "--"},
strings.Split(d.Command, " ")...),
Expand All @@ -163,7 +164,10 @@ func CmdMosaic(c *cli.Cli) error {
return deployer.Start(c.Context, p)
})

return wg.Wait()
err = wg.Wait()
slog.Info("done mosaic", "err", err)
return err

}

func diff(a map[string]string, b map[string]string) bool {
Expand Down
4 changes: 0 additions & 4 deletions cmd/sst/mosaic/multiplexer/multiplexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,23 @@ func (m *Model) update(ev tcell.Event) {
m.draw()
}
}

case tcell.KeyDown:
if m.focus == "sidebar" {
m.sidebarMove(1)
m.draw()
}

case tcell.KeyUp:
if m.focus == "sidebar" {
m.sidebarMove(-1)
m.draw()
return
}

case tcell.KeyCtrlZ:
if m.focus == "main" {
m.focus = "sidebar"
m.draw()
return
}

case tcell.KeyEnter:
if m.focus == "sidebar" && m.selectedPane().killable {
selected := m.selectedPane()
Expand Down
2 changes: 1 addition & 1 deletion cmd/sst/mosaic/server/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func Stream(ctx context.Context, url string, types ...interface{}) (chan any, er
var msg Message
err := decoder.Decode(&msg)
if err != nil {
continue
return
}
prototype, ok := registry[msg.Type]
if !ok {
Expand Down
33 changes: 33 additions & 0 deletions cmd/sst/mosaic/switcher/ecma48/color.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ecma48

import (
"fmt"
)

// Formats into ANSI escape code
func (c *Color) ToANSI(bg bool) string {
var offset int32
if bg {
offset = 10
} else {
offset = 0
}

switch c.ColorMode {
case ColorNone:
return fmt.Sprintf("\033[%dm", 39+offset)
case ColorBit3Normal:
return fmt.Sprintf("\033[%dm", 30+offset+c.Code)
case ColorBit3Bright:
return fmt.Sprintf("\033[%dm", 90+offset+c.Code)
case ColorBit8:
return fmt.Sprintf("\033[%d;5;%dm", 38+offset, c.Code)
case ColorBit24:
return fmt.Sprintf(
"\033[%d;2;%d;%d;%dm", 38+offset,
(c.Code>>16)&0xff, (c.Code>>8)&0xff, c.Code&0xff,
)
default:
panic(fmt.Sprintf("Unexpected ColorMode: %v", c.ColorMode))
}
}
196 changes: 196 additions & 0 deletions cmd/sst/mosaic/switcher/ecma48/parsed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package ecma48

// Output is the output of the parser
type Output struct {
Raw []rune
Parsed
}

// Parsed could be a simple character or maybe an escape sequence
type Parsed interface {
// Debug() string
// Raw() []byte
}

type EOF struct{}

// Unrecognized is when we don't understand the input
type Unrecognized string

type Esc struct{}

// Char is a single character that may occupy multiple cells
type Char struct {
Rune rune
IsWide bool
}

type OSCCursorQuery struct{}

// CtrlChar is for ctrl+[character]
type CtrlChar struct {
Char rune
}

// AltChar is for alt+[character]
type AltChar struct {
Char rune
}

// AltShiftChar is for alt+shift+[character]
type AltShiftChar struct {
Char rune
}

// Tab ('\t')
type Tab struct{}

// Newline ('\n')
type Newline struct{}

// CarriageReturn ('\r')
type CarriageReturn struct{}

// Backspace ('\b')
type Backspace struct{}

// Delete (0x7F)
type Delete struct{}

// CursorMovement is possibly caused by an arrow key
type CursorMovement struct {
Direction
N int

Alt bool
Shift bool
Ctrl bool
}

// RI (Reverse Index)
type RI struct{}

// PrivateDEC is DECSET/DECRST (DEC Private Mode Set/Reset)
type PrivateDEC struct {
On bool
Code int
}

// VPA (Vertical Line Position Absolute)
type VPA struct {
Y int
}

// CNL (Cursor Next Line)
type CNL struct {
YDiff uint
}

// CPL (Cursor Previous Line)
type CPL struct {
YDiff uint
}

// CHA (Cursor Horizontal Absolute)
type CHA struct {
X int
}

// CUP (Cursor Position)
type CUP struct {
X int
Y int
}

// ED (Erase in Display)
type ED struct {
Directive int
}

// EL (Erase in Line)
type EL struct {
Directive int
}

// ECH (Erase Characters)
type ECH struct {
N int
}

// IL (Insert Lines)
type IL struct {
N int
}

// ICH (Insert Characters)
type ICH struct {
N int
}

// DL (Delete Lines)
type DL struct {
N int
}

// DCH (Delete Characters)
type DCH struct {
N int
}

// DECSTBM (Set Scrolling Region). Bottom is -1 if it should be the bottom of the screen
type DECSTBM struct {
Top int
Bottom int
}

// SU (Scroll Up)
type SU struct {
N uint
}

// SD (Scroll Down)
type SD struct {
N uint
}

// SCOSC (Save Cursor Position)
type SCOSC struct{}

// SCORC (Restore Cursor Position)
type SCORC struct{}

type StyleReset struct{}

type StyleBold bool

type StyleConceal bool

type StyleCrossedOut bool

type StyleItalic bool

type StyleUnderline bool

type StyleFaint bool

type StyleReverse bool

type StyleForeground Color

type StyleBackground Color

type ScrollDown int

type ScrollUp int

type MouseDown struct {
X, Y int
}

type MouseUp struct {
X, Y int
}

type MouseDrag struct {
X, Y int
}
Loading

0 comments on commit 752ca08

Please sign in to comment.