Skip to content

Commit 3c87c4e

Browse files
committed
Introduced WAIT_EXIT_TIMEOUT to provide auto-exit without user input.
1 parent d914bf0 commit 3c87c4e

6 files changed

Lines changed: 58 additions & 6 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ Command to be used to perform reboot. Default value is "reboot".
132132
`CMD_SUSPEND`
133133
Command to be used to perform suspend. Default value is blank, but it tries to use "systemctl suspend", "loginctl suspend" or "zzz".
134134

135+
`WAIT_EXIT_TIMEOUT`
136+
Timeout in seconds before emptty automatically exits. If value is 0 or lower, there is no timeout. Default value is -1.
137+
135138
#### Commands
136139
If commands are allowed and default user is not defined, there could be used commands in login input or desktop selection. All of these commands need to start with colon `:`. Escape characters are ignored to prevent issues with muscle memory from VI.
137140
- `:help`, `:?` prints available commands

res/emptty.1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH EMPTTY 1 "December 2025" "emptty 0.15.0" emptty
1+
.TH EMPTTY 1 "March 2026" "emptty 0.15.0" emptty
22

33
.SH NAME
44
emptty \- Dead simple CLI Display Manager on TTY
@@ -199,6 +199,9 @@ Command to be used to perform reboot. Default value is "reboot".
199199
.IP CMD_SUSPEND
200200
Command to be used to perform suspend. Default value is blank, but it tries to use "systemctl suspend", "loginctl suspend" or "zzz".
201201

202+
.IP WAIT_EXIT_TIMEOUT
203+
Timeout in seconds before emptty automatically exits. If value is 0 or lower, there is no timeout. Default value is -1.
204+
202205
.SH COMMANDS
203206
If commands are allowed and default user is not defined, there could be used commands in login input. All of these commands need to start with colon ":". Escape characters are ignored to prevent issues with muscle memory from VI.
204207
- :help, :? - prints available commands

res/testing/conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ XORG_SESSIONS_PATH=/dev/null
3535
WAYLAND_SESSIONS_PATH=/dev/zero
3636
SELECT_LAST_USER=per-tty
3737
AUTO_SELECTION=true
38-
DEFAULT_ENV=wayland
38+
DEFAULT_ENV=wayland
39+
WAIT_EXIT_TIMEOUT=3

src/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type config struct {
4242
AutologinMaxRetry int `config:"AUTOLOGIN_MAX_RETRY" parser:"ParseInt" string:"StringInt" default:"2"`
4343
AutologinRtryPeriod int `config:"AUTOLOGIN_RETRY_PERIOD" parser:"ParsePositiveInt" string:"StringInt" default:"2"`
4444
Tty int `config:"TTY_NUMBER" parser:"ParseTTY" string:"StringInt" default:"7"`
45+
WaitExitTimeout int `config:"WAIT_EXIT_TIMEOUT" parser:"ParseWaitExitTimeout" default:"-1"`
4546
DefaultUser string `config:"DEFAULT_USER" parser:"SanitizeValue" default:""`
4647
DefaultSession string `config:"DEFAULT_SESSION" parser:"SanitizeValue" default:""`
4748
AutologinSession string `config:"AUTOLOGIN_SESSION" parser:"SanitizeValue" default:""`
@@ -64,6 +65,8 @@ type config struct {
6465
CmdSuspend string `config:"CMD_SUSPEND" parser:"SanitizeValue" default:""`
6566
}
6667

68+
var cfgWaitExitTimeout = -1
69+
6770
// LoadConfig handles loading of application configuration.
6871
func loadConfig(path string) *config {
6972
c := config{}
@@ -152,6 +155,12 @@ func (c *config) ParseInt(value, defaultValue string) int {
152155
return result
153156
}
154157

158+
// Parses int value for wait exit timeout and sets it into global variable.
159+
func (c *config) ParseWaitExitTimeout(value, defaultValue string) int {
160+
cfgWaitExitTimeout = c.ParseInt(value, defaultValue)
161+
return cfgWaitExitTimeout
162+
}
163+
155164
// Parses only positive int value from string.
156165
func (c *config) ParsePositiveInt(value, defaultValue string) int {
157166
result, _ := strconv.Atoi(sanitizeValue(value, defaultValue))

src/config_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ func TestLoadConfig(t *testing.T) {
176176
if conf.DefaultEnv != defaultEnvValue && defaultEnvValue != Wayland {
177177
t.Error("TestLoadConfig: DEFAULT_ENV value is not correct")
178178
}
179+
180+
if conf.WaitExitTimeout != 3 || cfgWaitExitTimeout != 3 {
181+
t.Error("TestLoadConfig: WAIT_EXIT_TIMEOUT value is not correct")
182+
}
179183
}
180184

181185
func TestLangLoadConfig(t *testing.T) {

src/utils.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strconv"
1313
"strings"
1414
"syscall"
15+
"time"
1516
"unsafe"
1617
)
1718

@@ -537,9 +538,40 @@ func chvt(tty int) bool {
537538
}
538539

539540
func waitForReturnToExit(code int) {
540-
fmt.Printf("\nPress Enter to continue...")
541-
if !TEST_MODE {
542-
bufio.NewReader(os.Stdin).ReadString('\n')
543-
os.Exit(code)
541+
if TEST_MODE {
542+
fmt.Printf("\nPress Enter to continue...")
543+
} else {
544+
remainingTimeout := cfgWaitExitTimeout
545+
if remainingTimeout <= 0 {
546+
fmt.Printf("\nPress Enter to continue...")
547+
bufio.NewReader(os.Stdin).ReadString('\n')
548+
os.Exit(code)
549+
return
550+
}
551+
552+
fmt.Printf("\nPress Enter to continue or wait %d seconds...", remainingTimeout)
553+
554+
inputDone := make(chan struct{})
555+
556+
go func() {
557+
bufio.NewReader(os.Stdin).ReadString('\n')
558+
close(inputDone)
559+
}()
560+
561+
ticker := time.NewTicker(time.Second)
562+
defer ticker.Stop()
563+
564+
for {
565+
select {
566+
case <-inputDone:
567+
os.Exit(code)
568+
case <-ticker.C:
569+
remainingTimeout--
570+
fmt.Printf("\r\033[KPress Enter to continue or wait %d seconds...", remainingTimeout)
571+
if remainingTimeout <= 0 {
572+
os.Exit(code)
573+
}
574+
}
575+
}
544576
}
545577
}

0 commit comments

Comments
 (0)