Skip to content

Commit

Permalink
minimal Tabber just returns impl
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Dec 23, 2024
1 parent 0e0b8dc commit 7148389
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 55 deletions.
4 changes: 2 additions & 2 deletions goal/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (gl *Goal) Set(cmdIO *exec.CmdIO, args ...string) error {
}
val := args[1]
if strings.Count(val, ":") > 1 || strings.Contains(val, "~") {
vl := stringsx.DedupeList(strings.Split(val, ":"))
vl := stringsx.UniqueList(strings.Split(val, ":"))
vl = AddHomeExpand([]string{}, vl...)
val = strings.Join(vl, ":")
}
Expand Down Expand Up @@ -175,7 +175,7 @@ func (gl *Goal) AddPath(cmdIO *exec.CmdIO, args ...string) error {
}
path := os.Getenv("PATH")
ps := strings.Split(path, ":")
ps = stringsx.DedupeList(ps)
ps = stringsx.UniqueList(ps)
ps = AddHomeExpand(ps, args...)
path = strings.Join(ps, ":")
err := os.Setenv("PATH", path)
Expand Down
14 changes: 7 additions & 7 deletions lab/filetree.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ func (fn *FileNode) OpenFile() error {
case fn.IsDir():
d := TensorFS(ofn)
dt := tensorfs.DirTable(d, nil)
ts.TensorTable(df, dt)
ts.AsLab().TensorTable(df, dt)
case fn.Info.Cat == fileinfo.Data:
switch fn.Info.Known {
case fileinfo.Tensor:
d := TensorFS(ofn)
ts.TensorEditor(df, d.Tensor)
ts.AsLab().TensorEditor(df, d.Tensor)
case fileinfo.Number:
dv := TensorFS(ofn)
v := dv.Tensor.Float1D(0)
Expand Down Expand Up @@ -183,7 +183,7 @@ func (fn *FileNode) OpenFile() error {
if err != nil {
core.ErrorSnackbar(fn, err)
} else {
ts.TensorTable(df, dt)
ts.AsLab().TensorTable(df, dt)
}
}
case fn.IsExec(): // todo: use exec?
Expand All @@ -203,7 +203,7 @@ func (fn *FileNode) OpenFile() error {
case fn.Info.Cat == fileinfo.Archive || fn.Info.Cat == fileinfo.Backup: // don't edit
fn.OpenFilesDefault()
default:
ts.EditorString(df, string(fn.Filepath))
ts.AsLab().EditorString(df, string(fn.Filepath))
}
return nil
}
Expand All @@ -230,7 +230,7 @@ func (fn *FileNode) EditFile() {
return
}
df := fsx.DirAndFile(string(fn.Filepath))
ts.EditorString(df, string(fn.Filepath))
ts.AsLab().EditorString(df, string(fn.Filepath))
}

// PlotFiles calls PlotFile on selected files
Expand All @@ -250,7 +250,7 @@ func (fn *FileNode) PlotFile() {
}
d := TensorFS(fn.AsNode())
if d != nil {
ts.PlotTensorFS(d)
ts.AsLab().PlotTensorFS(d)
return
}
if fn.Info.Cat != fileinfo.Data {
Expand All @@ -264,7 +264,7 @@ func (fn *FileNode) PlotFile() {
core.ErrorSnackbar(fn, err)
return
}
ts.PlotTable(ptab, dt)
ts.AsLab().PlotTable(ptab, dt)
}

// DiffDirs displays a browser with differences between two selected directories
Expand Down
53 changes: 7 additions & 46 deletions lab/tabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,47 +27,8 @@ var CurTabber Tabber
type Tabber interface {
core.Tabber

// AsDataTabs returns the underlying [databrowser.Tabs] widget.
AsDataTabs() *Tabs

// TensorTable recycles a tab with a [tensorcore.Table] widget
// to view given [table.Table], using its own table.Table.
TensorTable(label string, dt *table.Table) *tensorcore.Table

// TensorEditor recycles a tab with a [tensorcore.TensorEditor] widget
// to view given Tensor.
TensorEditor(label string, tsr tensor.Tensor) *tensorcore.TensorEditor

// TensorGrid recycles a tab with a [tensorcore.TensorGrid] widget
// to view given Tensor.
TensorGrid(label string, tsr tensor.Tensor) *tensorcore.TensorGrid

// PlotTable recycles a tab with a Plot of given [table.Table].
PlotTable(label string, dt *table.Table) *plotcore.PlotEditor

// PlotTensorFS recycles a tab with a Plot of given [tensorfs.Node],
// automatically using the Dir/File name of the data node for the label.
PlotTensorFS(dfs *tensorfs.Node) *plotcore.PlotEditor

// GoUpdatePlot calls GoUpdatePlot on plot at tab with given name.
// Does nothing if tab name doesn't exist (returns nil).
GoUpdatePlot(label string) *plotcore.PlotEditor

// UpdatePlot calls UpdatePlot on plot at tab with given name.
// Does nothing if tab name doesn't exist (returns nil).
UpdatePlot(label string) *plotcore.PlotEditor

// todo: PlotData of plot.Node

// SliceTable recycles a tab with a [core.Table] widget
// to view the given slice of structs.
SliceTable(label string, slc any) *core.Table

// EditorString recycles a [texteditor.Editor] tab, displaying given string.
EditorString(label, content string) *texteditor.Editor

// EditorFile opens an editor tab for given file.
EditorFile(label, filename string) *texteditor.Editor
// AsLab returns the [lab.Tabs] widget with all the tabs methods.
AsLab() *Tabs
}

// NewTab recycles a tab with given label, or returns the existing one
Expand All @@ -76,7 +37,7 @@ type Tabber interface {
// mkfun function is called to create and configure a new widget
// if not already existing.
func NewTab[T any](tb Tabber, label string, mkfun func(tab *core.Frame) T) T {
tab := tb.RecycleTab(label)
tab := tb.AsLab().RecycleTab(label)
var zv T
if tab.HasChildren() {
nc := tab.NumChildren()
Expand All @@ -85,7 +46,7 @@ func NewTab[T any](tb Tabber, label string, mkfun func(tab *core.Frame) T) T {
return tt
}
err := fmt.Errorf("Name / Type conflict: tab %q does not have the expected type of content: is %T", label, lc)
core.ErrorSnackbar(tb.AsDataTabs(), err)
core.ErrorSnackbar(tb.AsLab(), err)
return zv
}
w := mkfun(tab)
Expand All @@ -95,7 +56,7 @@ func NewTab[T any](tb Tabber, label string, mkfun func(tab *core.Frame) T) T {
// TabAt returns widget of given type at tab of given name, nil if tab not found.
func TabAt[T any](tb Tabber, label string) T {
var zv T
tab := tb.TabByName(label)
tab := tb.AsLab().TabByName(label)
if tab == nil {
return zv
}
Expand All @@ -109,7 +70,7 @@ func TabAt[T any](tb Tabber, label string) T {
}

err := fmt.Errorf("Name / Type conflict: tab %q does not have the expected type of content: %T", label, lc)
core.ErrorSnackbar(tb.AsDataTabs(), err)
core.ErrorSnackbar(tb.AsLab(), err)
return zv
}

Expand All @@ -123,7 +84,7 @@ func (ts *Tabs) Init() {
ts.Type = core.FunctionalTabs
}

func (ts *Tabs) AsDataTabs() *Tabs {
func (ts *Tabs) AsLab() *Tabs {
return ts
}

Expand Down

0 comments on commit 7148389

Please sign in to comment.