Skip to content

Commit

Permalink
Reduced the number of screen updates, added support for "AdiIrc" (log…
Browse files Browse the repository at this point in the history
… syntax is same as mIrc.
  • Loading branch information
Holladiewal committed Jan 1, 2018
1 parent 72ec441 commit a43a4a4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
8 changes: 2 additions & 6 deletions src/Definition.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Rescue(client : String, clientSystem : System, language : String, number :



var rats : WatchableMutableList<Rat> = WatchableMutableList(::updateScreen)
var rats : WatchableMutableList<Rat> = WatchableMutableList(::noop)
var notes : WatchableMutableList<String> = WatchableMutableList(::updateScreen)

override fun hashCode(): Int {
Expand All @@ -46,8 +46,4 @@ enum class Trilean{
TRUE, FALSE, NEUTRAL;
}

fun rescueChanged(prop : Any, old : Any, new : Any){
//println()
//if (old != new)
//updateScreen()
}
fun rescueChanged(prop : Any, old : Any, new : Any) = Unit
2 changes: 2 additions & 0 deletions src/LogHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ open class listener : TailerListenerAdapter(){
handleMessage(nick, line)
}

fun adiirc(l : String?) = mirc(l)

fun mirc(l : String?){
var line : String = l!!.replace("\t", " ")
val nick = line.split(Pattern.compile(" "), 3)[1].replace("<", "").replace(">", "").replace("+", "").replace("%", "").replace("@", "").replace("~", "").replace("&", "") // strip: +%@~&
Expand Down
55 changes: 28 additions & 27 deletions src/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ fun updateScreen() {
//terminal!!.exitPrivateMode()
}

fun Terminal.printString(input : String, x : Int, y : Int, color : Pair<TextColor, TextColor> = Pair(TextColor.ANSI.WHITE, TextColor.ANSI.BLACK), reversed : Boolean = false){
fun Terminal.printString(input : String, x : Int, y : Int, color : Pair<TextColor, TextColor> = Pair(TextColor.ANSI.WHITE, TextColor.ANSI.BLACK), reversed : Boolean = false, noflush : Boolean = false){
@Suppress("NAME_SHADOWING")
val color = if (reversed){Pair(color.second, color.first)} else {color}
val coords = this.cursorPosition
Expand All @@ -164,7 +164,7 @@ fun Terminal.printString(input : String, x : Int, y : Int, color : Pair<TextColo
input.toCharArray().forEach {
this.putCharacter(it)
}
flush()
if (!noflush) flush()
this.cursorPosition = coords
}

Expand All @@ -180,15 +180,15 @@ fun printRescues() : Int {
if (!res.active) {
terminal?.enableSGR(SGR.REVERSE)
}
terminal?.printString("${res.number} |", charCount + 2, linecount + 2, colors)
terminal?.printString("${res.number} |", charCount + 2, linecount + 2, colors, noflush=true)
charCount += res.number.toString().length + 2
terminal?.printString(" ${res.client} |", charCount + 2, linecount + 2, colors)
terminal?.printString(" ${res.client} |", charCount + 2, linecount + 2, colors, noflush=true)
charCount += res.client.length + 3
terminal?.printString(" ${res.language} |", charCount + 2, linecount + 2, colors)
terminal?.printString(" ${res.language} |", charCount + 2, linecount + 2, colors, noflush=true)
charCount += res.language.length + 3
terminal?.printString(" ${res.platform} |", charCount + 2, linecount + 2, colors)
terminal?.printString(" ${res.platform} |", charCount + 2, linecount + 2, colors, noflush=true)
charCount += res.platform.length + 3
terminal?.printString(" ${res.clientSystem.name}", charCount + 2, linecount + 2, colors)
terminal?.printString(" ${res.clientSystem.name}", charCount + 2, linecount + 2, colors, noflush=true)
charCount += res.clientSystem.name.length + 1
if (!res.active) {
terminal?.disableSGR(SGR.REVERSE)
Expand All @@ -197,6 +197,7 @@ fun printRescues() : Int {
//printNotes

colors = Pair(TextColor.ANSI.WHITE, TextColor.ANSI.BLACK)
terminal?.flush()
}
} catch (e: Exception) {
}
Expand All @@ -210,40 +211,40 @@ fun printStatus(res: Rescue, lCount : Int) : Int{
terminal?.printString(name + ": ", charCount + 3, lineCount + 2, blackwhite)
charCount += name.length + 2

if (status.friended == TRUE) terminal?.printString("FR+", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.MAGENTA, TextColor.ANSI.WHITE), true)
if (status.friended == NEUTRAL) {terminal?.printString("FR-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true)}
if (status.friended == FALSE) {terminal?.printString("FR-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.RED, TextColor.ANSI.WHITE), true)}
if (status.friended == TRUE) terminal?.printString("FR+", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.MAGENTA, TextColor.ANSI.WHITE), true, true)
if (status.friended == NEUTRAL) {terminal?.printString("FR-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true, true)}
if (status.friended == FALSE) {terminal?.printString("FR-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.RED, TextColor.ANSI.WHITE), true, true)}
charCount += 3 + 1

if (status.winged == TRUE) terminal?.printString("WR+", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.CYAN, TextColor.ANSI.WHITE), true)
if (status.winged == NEUTRAL) terminal?.printString("WR-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true)
if (status.winged == FALSE) terminal?.printString("WR-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.RED, TextColor.ANSI.WHITE), true)
if (status.winged == TRUE) terminal?.printString("WR+", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.CYAN, TextColor.ANSI.WHITE), true, true)
if (status.winged == NEUTRAL) terminal?.printString("WR-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true, true)
if (status.winged == FALSE) terminal?.printString("WR-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.RED, TextColor.ANSI.WHITE), true, true)
charCount += 3 + 1

if (status.beacon == TRUE) terminal?.printString("Beacon+", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLUE, TextColor.ANSI.WHITE), true)
if (status.beacon == NEUTRAL) terminal?.printString("Beacon-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true)
if (status.beacon == FALSE) terminal?.printString("Beacon-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.RED, TextColor.ANSI.WHITE), true)
if (status.beacon == TRUE) terminal?.printString("Beacon+", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLUE, TextColor.ANSI.WHITE), true, true)
if (status.beacon == NEUTRAL) terminal?.printString("Beacon-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true, true)
if (status.beacon == FALSE) terminal?.printString("Beacon-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.RED, TextColor.ANSI.WHITE), true, true)
charCount += 7 + 1

if (status.inSys == TRUE) terminal?.printString("Sys+", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.YELLOW, TextColor.ANSI.WHITE), true)
if (status.inSys == NEUTRAL) terminal?.printString("Sys-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true)
if (status.inSys == TRUE) terminal?.printString("Sys+", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.YELLOW, TextColor.ANSI.WHITE), true, true)
if (status.inSys == NEUTRAL) terminal?.printString("Sys-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true, true)
charCount += 4 + 1

if (status.fueled == TRUE) terminal?.printString("Fuel+", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.GREEN, TextColor.ANSI.WHITE), true)
else terminal?.printString("", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true)
if (status.fueled == TRUE) terminal?.printString("Fuel+", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.GREEN, TextColor.ANSI.WHITE), true, true)
else terminal?.printString("", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true, true)
charCount += 5 + 1

if (status.disconnected == TRUE) terminal?.printString("DC", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.RED, TextColor.ANSI.WHITE), true)
else terminal?.printString("", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true)
if (status.disconnected == TRUE) terminal?.printString("DC", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.RED, TextColor.ANSI.WHITE), true, true)
else terminal?.printString("", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true, true)
charCount += 2 + 1

if (status.instancingP == TRUE) terminal?.printString("Inst-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.RED, TextColor.ANSI.WHITE), true)
if (status.instancingP == NEUTRAL) terminal?.printString("", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true)
if (status.instancingP == FALSE) terminal?.printString("", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.GREEN), true)
if (status.instancingP == TRUE) terminal?.printString("Inst-", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.RED, TextColor.ANSI.WHITE), true, true)
if (status.instancingP == NEUTRAL) terminal?.printString("", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true, true)
if (status.instancingP == FALSE) terminal?.printString("", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.GREEN), true, true)
charCount += 5 + 1

if (status.interdicted == TRUE) terminal?.printString("INT", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.RED, TextColor.ANSI.WHITE), true)
else terminal?.printString("", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true)
if (status.interdicted == TRUE) terminal?.printString("INT", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.RED, TextColor.ANSI.WHITE), true, true)
else terminal?.printString("", charCount + 3, lineCount + 2, Pair(TextColor.ANSI.BLACK, TextColor.ANSI.WHITE), true, true)
charCount += 3 + 1

lineCount++
Expand Down
5 changes: 3 additions & 2 deletions src/WebSocketHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fun parseRescueRead(meta: JsonObject, data : JsonArray){

}
}
updateScreen()
launch{ delay(255); updateScreen()}
}

fun parseRescueUpdate(meta: JsonObject, data: JsonArray){
Expand Down Expand Up @@ -219,6 +219,7 @@ fun parseRescueUpdate(meta: JsonObject, data: JsonArray){
ratsNow
.filterNot { rat -> rats.map { it.uuid }.contains(rat) }
.forEach { rats.add(Rat(resolveRatName(it), uuid= it)) }

attributes.get("unidentifiedRats").asJsonArray.forEach { rats.add(Rat(it.asString, uuid="-1").setNameCorrectly())}

/*
Expand All @@ -243,7 +244,7 @@ fun parseRescueUpdate(meta: JsonObject, data: JsonArray){


}
updateScreen()
// updateScreen()
launch{ delay(255); updateScreen()}

}
Expand Down

0 comments on commit a43a4a4

Please sign in to comment.