commit 9cbfcba

delthas  ·  2023-08-10 09:28:38 +0000 UTC
parent fe1216b
Add the transient config option

This enables ephemeral, no disk runs for e.g. public instances.
5 files changed,  +35, -9
M app.go
M app.go
+4, -0
 1@@ -1124,6 +1124,10 @@ func (app *App) notifyHighlight(buffer, nick, content string) {
 2 		app.win.Notify(nick, content)
 3 	}
 4 
 5+	if app.cfg.Transient {
 6+		return
 7+	}
 8+
 9 	path := app.cfg.OnHighlightPath
10 	if path == "" {
11 		defaultHighlightPath, err := DefaultHighlightPath()
+11, -8
 1@@ -4,7 +4,6 @@ import (
 2 	"errors"
 3 	"flag"
 4 	"fmt"
 5-	"io/ioutil"
 6 	"math/rand"
 7 	"os"
 8 	"os/signal"
 9@@ -126,9 +125,11 @@ func main() {
10 		panic(err)
11 	}
12 
13-	lastNetID, lastBuffer := getLastBuffer()
14-	app.SwitchToBuffer(lastNetID, lastBuffer)
15-	app.SetLastClose(getLastStamp())
16+	if !cfg.Transient {
17+		lastNetID, lastBuffer := getLastBuffer()
18+		app.SwitchToBuffer(lastNetID, lastBuffer)
19+		app.SetLastClose(getLastStamp())
20+	}
21 
22 	sigCh := make(chan os.Signal, 1)
23 	signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
24@@ -140,8 +141,10 @@ func main() {
25 
26 	app.Run()
27 	app.Close()
28-	writeLastBuffer(app)
29-	writeLastStamp(app)
30+	if !cfg.Transient {
31+		writeLastBuffer(app)
32+		writeLastStamp(app)
33+	}
34 }
35 
36 func cachePath() string {
37@@ -162,7 +165,7 @@ func lastBufferPath() string {
38 }
39 
40 func getLastBuffer() (netID, buffer string) {
41-	buf, err := ioutil.ReadFile(lastBufferPath())
42+	buf, err := os.ReadFile(lastBufferPath())
43 	if err != nil {
44 		return "", ""
45 	}
46@@ -189,7 +192,7 @@ func lastStampPath() string {
47 }
48 
49 func getLastStamp() time.Time {
50-	buf, err := ioutil.ReadFile(lastStampPath())
51+	buf, err := os.ReadFile(lastStampPath())
52 	if err != nil {
53 		return time.Time{}
54 	}
+3, -0
 1@@ -535,6 +535,9 @@ func commandDoQuit(app *App, args []string) (err error) {
 2 }
 3 
 4 func commandDoQuote(app *App, args []string) (err error) {
 5+	if app.cfg.Transient {
 6+		return fmt.Errorf("usage of QUOTE is disabled")
 7+	}
 8 	s := app.CurrentSession()
 9 	if s == nil {
10 		return errOffline
+11, -1
 1@@ -74,7 +74,8 @@ type Config struct {
 2 
 3 	Colors ui.ConfigColors
 4 
 5-	Debug bool
 6+	Debug     bool
 7+	Transient bool
 8 }
 9 
10 func DefaultHighlightPath() (string, error) {
11@@ -363,6 +364,15 @@ func unmarshal(filename string, cfg *Config) (err error) {
12 			if cfg.Debug, err = strconv.ParseBool(debug); err != nil {
13 				return err
14 			}
15+		case "transient":
16+			var transient string
17+			if err := d.ParseParams(&transient); err != nil {
18+				return err
19+			}
20+
21+			if cfg.Transient, err = strconv.ParseBool(transient); err != nil {
22+				return err
23+			}
24 		default:
25 			return fmt.Errorf("unknown directive %q", d.Name)
26 		}
+6, -0
 1@@ -180,9 +180,15 @@ colors {
 2 :  color scheme for user nicks, either "base" (the default, 16 colors) or "extended" (256 colors)
 3 
 4 *debug*
 5+	Advanced.
 6 	Dump all sent and received data to the home buffer, useful for debugging.
 7 	Defaults to false.
 8 
 9+*-transient*
10+	Advanced.
11+	Run an ephemeral instance without disk reads/writes (except for the initial
12+	configuration).
13+
14 # EXAMPLES
15 
16 A minimal configuration file to connect to Libera.Chat as "Guest123456":