Documentation
¶
Overview ¶
Package serve shows the notebook in a web browser, for mdsh --serve. It serves the pages in web, the same ones mdsh-gui shows, and stands in for the Wails runtime they talk to: calls to ui.App are POSTs to /wails/call, and events come over a WebSocket.
Each browser tab showing window.html is one of the App's windows, named in its URL. A window lasts until its last tab closes, not when the browser tab does, so its shells keep running and opening the server's address again picks it up.
Anyone who can reach the server can run commands as the user who started it, so every request needs the token printed at start: the first visit gives it in the URL and gets a cookie for it.
Index ¶
- Constants
- type Options
- type Server
- func (s *Server) Ask(win ui.Window, q ui.Question)
- func (s *Server) CLIState() ui.CLI
- func (s *Server) ChooseFile(ctx context.Context, title, dir string) (string, error)
- func (s *Server) ChooseFolder(ctx context.Context, title, dir string) (string, error)
- func (s *Server) Console() *ui.Console
- func (s *Server) CopyGIF([]byte) error
- func (s *Server) CopySecret(text string, clear time.Duration) error
- func (s *Server) Current() (uint, bool)
- func (s *Server) EmitAll(name string, data any)
- func (s *Server) Handler() http.Handler
- func (s *Server) InstallCLI() (ui.CLI, error)
- func (s *Server) ListenAndServe(ctx context.Context) error
- func (s *Server) Local() bool
- func (s *Server) NewWindow(file string) ui.Window
- func (s *Server) OnMain(fn func())
- func (s *Server) OpenFile(file string) error
- func (s *Server) OpenFiles(win ui.Window, dir string) ([]string, error)
- func (s *Server) OpenURL(url string) error
- func (s *Server) Quit()
- func (s *Server) RecentChanged()
- func (s *Server) Reveal(file string) error
- func (s *Server) SaveFile(win ui.Window, sf ui.SaveFile) (string, error)
- func (s *Server) Serve(ctx context.Context, l net.Listener) error
- func (s *Server) ServeStdio(ctx context.Context, in io.Reader, out io.Writer) error
- func (s *Server) ShowError(win ui.Window, err error)
- func (s *Server) ShowView(ui.View)
- func (s *Server) Token() string
- func (s *Server) URL(l net.Listener) string
- func (s *Server) UninstallCLI() (ui.CLI, error)
- func (s *Server) WindowOf(ctx context.Context) (uint, bool)
Constants ¶
const DefaultAddr = "127.0.0.1:8080"
DefaultAddr is where --serve listens when given no address: this machine only.
const Stdio = "stdio"
Stdio is the --serve address that serves on stdin and stdout.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
Addr string // host:port to listen on; a missing host or port is filled in from DefaultAddr
Settings *settings.Store
Cwd string // the folder mdsh started in
Dir string // the folder named on the command line, if any
File string // the file to open in the first window, if any
Args []string // its arguments
Source string // what the files given to --source hold, for every shell to source
Token string // the access token; "" makes a random one
Log io.Writer
Build ui.Build // the program's build, for the About tab
// LSP is the command that runs the language server for a file, for
// the Neovim source pane, or nil for none.
LSP func(file string) []string
// Trust remembers which files' env.source files may be read into
// their shells, as mdsh-gui's does; nil remembers none, so each file
// asks every time.
Trust *trust.Store
}
Options say what to serve and where.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a running mdsh --serve.
func (*Server) CLIState ¶
CLIState is the zero CLI: mdsh --serve carries no bundled mdsh, so Settings hides the Command line tool row.
func (*Server) ChooseFile ¶
func (*Server) ChooseFolder ¶
func (*Server) Console ¶
Console is the log the Console pane shows. Log to it with a handler from ui.NewConsoleHandler.
func (*Server) CopyGIF ¶
CopyGIF can't put an image on the clipboard from here, so the page copies the recording's text instead.
func (*Server) CopySecret ¶
CopySecret has the page in front put text on the clipboard, and take it off again after clear if it is still there. A browser has no way to keep it out of clipboard history.
func (*Server) InstallCLI ¶
InstallCLI can't: only the desktop app carries mdsh to install.
func (*Server) ListenAndServe ¶
ListenAndServe listens on the address in Options and serves until ctx ends.
func (*Server) OpenFile ¶
OpenFile opens file in a new browser tab, as the server serves files beside open documents.
func (*Server) OpenURL ¶
OpenURL opens url in a new browser tab, from the window in front. runtime.js opens web links itself, as the click happens, so this is for what gets past it.
func (*Server) Quit ¶
func (s *Server) Quit()
Quit does nothing: the server runs until it is stopped.
func (*Server) RecentChanged ¶
func (s *Server) RecentChanged()
RecentChanged does nothing: pages have no Open Recent menu.
func (*Server) ServeStdio ¶
ServeStdio serves one client on in and out, as mdsh --serve=stdio does, until in ends or ctx does, then closes every window's shells.
func (*Server) UninstallCLI ¶
UninstallCLI can't, for the same reason.