comparison src/main/kotlin/name/blackcap/passman/Main.kt @ 27:3a3067ba673b

Add idle-time detection to interactive mode, clean up imports.
author David Barts <n5jrn@me.com>
date Sat, 27 Jul 2024 09:50:54 -0700
parents 2188b2f13326
children 287eadf5ab30
comparison
equal deleted inserted replaced
26:69526ae8c8de 27:3a3067ba673b
1 package name.blackcap.passman 1 package name.blackcap.passman
2 2
3 import java.io.BufferedReader
4 import java.io.InputStreamReader
5 import java.util.* 3 import java.util.*
6 import java.util.stream.Collectors
7 import kotlin.reflect.jvm.javaMethod
8 import kotlin.reflect.jvm.kotlinFunction
9 import kotlin.system.exitProcess 4 import kotlin.system.exitProcess
10 5
11 fun main(args: Array<String>) { 6 fun main(args: Array<String>) {
12 val NOPASSWORD = setOf<String>("help", "quit") 7 val NOPASSWORD = setOf<String>("help", "quit")
13 if (args.isEmpty()) { 8 if (args.isEmpty()) {
45 } 40 }
46 41
47 fun runInteractive() { 42 fun runInteractive() {
48 val DISALLOWED = setOf<String>("password") 43 val DISALLOWED = setOf<String>("password")
49 val QUIT = setOf<String>("exit", "quit") 44 val QUIT = setOf<String>("exit", "quit")
45 val MAX_TIME_MILLIS = 10L * 60L * 1000L
50 var lastStatus = 0 46 var lastStatus = 0
51 println("This is PassMan interactive mode. Type help for help.") 47 println("This is PassMan interactive mode. Type help for help.")
52 while (true) { 48 while (true) {
49 val beforeRead = System.currentTimeMillis()
53 val rawLine = System.console()?.readLine("passman> ") 50 val rawLine = System.console()?.readLine("passman> ")
54 if (rawLine == null) { 51 if (rawLine == null) {
55 println() // ensure shell prompt comes out on a line of its own 52 println() // ensure shell prompt comes out on a line of its own
53 break
54 }
55 if (System.currentTimeMillis() - beforeRead > MAX_TIME_MILLIS) {
56 error("time limit exceeded, goodbye!")
57 lastStatus = 1
56 break 58 break
57 } 59 }
58 val s = Shplitter() 60 val s = Shplitter()
59 s.feed(rawLine) 61 s.feed(rawLine)
60 if (!s.complete) { 62 if (!s.complete) {