serve

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 28 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const DefaultAddr = "127.0.0.1:8080"

DefaultAddr is where --serve listens when given no address: this machine only.

View Source
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 New

func New(opts Options) (*Server, error)

New makes a Server for opts. Serve or ListenAndServe start it.

func (*Server) Ask

func (s *Server) Ask(win ui.Window, q ui.Question)

func (*Server) CLIState

func (s *Server) CLIState() ui.CLI

CLIState is the zero CLI: mdsh --serve carries no bundled mdsh, so Settings hides the Command line tool row.

func (*Server) ChooseFile

func (s *Server) ChooseFile(ctx context.Context, title, dir string) (string, error)

func (*Server) ChooseFolder

func (s *Server) ChooseFolder(ctx context.Context, title, dir string) (string, error)

func (*Server) Console

func (s *Server) Console() *ui.Console

Console is the log the Console pane shows. Log to it with a handler from ui.NewConsoleHandler.

func (*Server) CopyGIF

func (s *Server) CopyGIF([]byte) error

CopyGIF can't put an image on the clipboard from here, so the page copies the recording's text instead.

func (*Server) CopySecret

func (s *Server) CopySecret(text string, clear time.Duration) error

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) Current

func (s *Server) Current() (uint, bool)

func (*Server) EmitAll

func (s *Server) EmitAll(name string, data any)

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler is the server's HTTP handler.

func (*Server) InstallCLI

func (s *Server) InstallCLI() (ui.CLI, error)

InstallCLI can't: only the desktop app carries mdsh to install.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(ctx context.Context) error

ListenAndServe listens on the address in Options and serves until ctx ends.

func (*Server) Local

func (s *Server) Local() bool

Local reports whether the server only listens on this machine.

func (*Server) NewWindow

func (s *Server) NewWindow(file string) ui.Window

NewWindow makes a window, and asks the page in front to open it.

func (*Server) OnMain

func (s *Server) OnMain(fn func())

func (*Server) OpenFile

func (s *Server) OpenFile(file string) error

OpenFile opens file in a new browser tab, as the server serves files beside open documents.

func (*Server) OpenFiles

func (s *Server) OpenFiles(win ui.Window, dir string) ([]string, error)

func (*Server) OpenURL

func (s *Server) OpenURL(url string) error

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) Reveal

func (s *Server) Reveal(file string) error

Reveal can't show a file manager in the browser.

func (*Server) SaveFile

func (s *Server) SaveFile(win ui.Window, sf ui.SaveFile) (string, error)

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, l net.Listener) error

Serve serves on l until ctx ends, then closes every window's shells.

func (*Server) ServeStdio

func (s *Server) ServeStdio(ctx context.Context, in io.Reader, out io.Writer) error

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) ShowError

func (s *Server) ShowError(win ui.Window, err error)

func (*Server) ShowView

func (s *Server) ShowView(ui.View)

ShowView does nothing: pages have no View menu.

func (*Server) Token

func (s *Server) Token() string

Token is the access token.

func (*Server) URL

func (s *Server) URL(l net.Listener) string

URL is the address to open, token included, once the server listens on l.

func (*Server) UninstallCLI

func (s *Server) UninstallCLI() (ui.CLI, error)

UninstallCLI can't, for the same reason.

func (*Server) WindowOf

func (s *Server) WindowOf(ctx context.Context) (uint, bool)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL