Skip to content

Commit

Permalink
Change paste content widths and add line numbering (#61)
Browse files Browse the repository at this point in the history
* Lock paste width so page doesn't scroll horizontally

* Changed text input to use variable width instead of fixed columns

* Properly wrap paste content, add toggleable line numbers

* Document variable changes

* Opt-in to new changes; Add word wrap toggle
  • Loading branch information
auravoid authored Aug 20, 2024
1 parent 3de85c3 commit f843ec5
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 16 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ nix build .#portable-service
These configuration options are available as command-line flags and
environment variables. All of them are optional.

| Command-line flag | Environment variable | Default value | Description |
| -------------------- | -------------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------ |
| `-hostname` | `TSNET_HOSTNAME` | `paste` | The hostname to use on your tailnet. |
| `-data-location` | `DATA_DIR` | `~/.config/tailscale/paste` | Where program data is stored. |
| `-tsnet-verbose` | `TSNET_VERBOSE` | `false` | If set, tsnet will log verbosely to stderr. |
| `-use-funnel` | `USE_FUNNEL` | `false` | If set, expose individual pastes to the public internet with [Funnel](https://tailscale.com/kb/1223/funnel). |
| `-hide-funnel-users` | `HIDE_FUNNEL_USERS` | `false` | If set, don't display the username and profile picture of the user who created the paste in funneled pastes. |
| `-http-port` | `HTTP_PORT` | unset | If set, expose individual pastes on a HTTP server running on the given port. |
| `-control-url` | `TSNET_CONTROL_URL` | unset | If set, a custom control server to use, e.g. for Headscale users. |
| `-disable-https` | `DISABLE_HTTPS` | `false` | If set, disable serving on HTTPS with Serve. Useful for Headscale deployments. |
| Command-line flag | Environment variable | Default value | Description |
| ----------------------- | ---------------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------ |
| `-hostname` | `TSNET_HOSTNAME` | `paste` | The hostname to use on your tailnet. |
| `-data-location` | `DATA_DIR` | `~/.config/tailscale/paste` | Where program data is stored. |
| `-tsnet-verbose` | `TSNET_VERBOSE` | `false` | If set, tsnet will log verbosely to stderr. |
| `-use-funnel` | `USE_FUNNEL` | `false` | If set, expose individual pastes to the public internet with [Funnel](https://tailscale.com/kb/1223/funnel). |
| `-hide-funnel-users` | `HIDE_FUNNEL_USERS` | `false` | If set, don't display the username and profile picture of the user who created the paste in funneled pastes. |
| `-http-port` | `HTTP_PORT` | unset | If set, expose individual pastes on a HTTP server running on the given port. |
| `-control-url` | `TSNET_CONTROL_URL` | unset | If set, a custom control server to use, e.g. for Headscale users. |
| `-disable-https` | `DISABLE_HTTPS` | `false` | If set, disable serving on HTTPS with Serve. Useful for Headscale deployments. |
| `-enable-line-numbers` | `ENABLE_LINE_NUMBERS` | `false` | If set, enable line numbers being shown when viewing a paste. |
| `-enable-word-wrap` | `ENABLE_WORD_WRAP` | `false` | If set, allows lines to break and wrap to the following line. |

## Deploying

Expand Down
18 changes: 17 additions & 1 deletion cmd/tclipd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ var (
httpPort = flag.String("http-port", envOr("HTTP_PORT", ""), "optional http port to start an http server on, e.g for reverse proxies. will only serve funnel endpoints")
controlUrl = flag.String("control-url", envOr("TSNET_CONTROL_URL", ""), "optional alternate control server URL to use, for e.g. headscale")
disableHTTPS = flag.Bool("disable-https", hasEnv("DISABLE_HTTPS"), "disable http serve, required for Headscale support")
enableLineNumbers = flag.Bool("enable-line-numbers", hasEnv("ENABLE_LINE_NUMBERS"), "enables line numbers on paste content")
enableWordWrap = flag.Bool("enable-word-wrap", hasEnv("ENABLE_WORD_WRAP"), "enable word wrap on paste content")

//go:embed schema.sql
sqlSchema string
Expand Down Expand Up @@ -514,7 +516,7 @@ INNER JOIN users u
WHERE p.id = ?1`

row := s.db.QueryRowContext(r.Context(), q, id)
var fname, data, userLoginName, userDisplayName, userProfilePicURL string
var fname, data, userLoginName, userDisplayName, userProfilePicURL, lineNumbersClass, wordWrapClass string
var userID int64
var createdAt string

Expand All @@ -537,6 +539,16 @@ WHERE p.id = ?1`
cssClass = fmt.Sprintf("lang-%s", strings.ToLower(lang))
}

lineNumbersClass = "no-line-numbers"
if *enableLineNumbers {
lineNumbersClass = "line-numbers"
}

wordWrapClass = "word-wrap-off"
if *enableWordWrap {
wordWrapClass = "word-wrap-on"
}

p := bluemonday.UGCPolicy()
p.AllowAttrs("class").Matching(regexp.MustCompile("^language-[a-zA-Z0-9]+$")).OnElements("code")

Expand Down Expand Up @@ -654,6 +666,8 @@ WHERE p.id = ?1`
Data string
RawHTML *template.HTML
CSSClass string
EnableLineNumbers string
EnableWordWrap string
}{
UserInfo: up,
Title: fname,
Expand All @@ -667,6 +681,8 @@ WHERE p.id = ?1`
Data: data,
RawHTML: rawHTML,
CSSClass: cssClass,
EnableLineNumbers: lineNumbersClass,
EnableWordWrap: wordWrapClass,
})
if err != nil {
log.Printf("%s: %v", r.RemoteAddr, err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/tclipd/static/css/prism.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f843ec5

Please sign in to comment.