Thin the app's comments
The same pass the server had, on the Kotlin side: comments restating what the code says are gone, and the ones recording a measurement, a constraint or an incident are kept but cut to a few lines each. 6540 comment lines to 5674, and 920 lines off the app. Two doc comments had drifted onto the item above the one they describe -- `contextAfter`'s onto `sessionWorking` in Events.kt, and `UsageMonitor`'s equivalent on the server was fixed in the previous commit. Each is back on its own item, which is the only non-comment line this diff moves. The comments are reflowed to the column limit at their own indentation: several were written wide, and ktfmt re-wrapped them into lines holding a single orphan word. `/tmp` script, not kept -- ktfmt is idempotent over the result, which is the check. Left alone deliberately: this codebase's remaining comment density is high because the comments carry things the code cannot say -- what a null means, what a number was measured against, which bug a guard exists for. Of the 238 one-line doc comments in the app, five were pure restatement of the name and were removed; the rest each say something the signature does not. ktfmtFormat, compileDebugKotlin, lintDebug and testDebugUnitTest pass; cargo test (127), clippy --all-targets and fmt still clean. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
79682f03a7
commit
edc39c7371
68 files changed
+2077
-2997
No files matched your search
@@ -13,9 +13,8 @@ import androidx.compose.ui.text.style.TextDecoration
|
||||
*
|
||||
* Its own palette rather than the syntax one: a program that prints in red has chosen red, where a
|
||||
* highlighter's colours are this app's reading of somebody else's code. They come out of the same
|
||||
* Catppuccin values (see `ansiPalette` in `Theme.kt`) so nothing on screen is a colour from
|
||||
* somewhere else, but the two are not one table and must not become one -- adding a syntax role to
|
||||
* this list would silently move `ls`'s directory blue.
|
||||
* Catppuccin values so nothing on screen is a colour from somewhere else, but the two are not one
|
||||
* table -- adding a syntax role to this list would silently move `ls`'s directory blue.
|
||||
*/
|
||||
data class AnsiPalette(
|
||||
/** Indexes 0-7, then 8-15 bright, in the terminal's own order. */
|
||||
@@ -30,19 +29,18 @@ data class AnsiPalette(
|
||||
* What a tool printed, with its terminal styling applied and everything else taken out.
|
||||
*
|
||||
* Bash output arrives exactly as the program wrote it, escape sequences included, and drawn
|
||||
* verbatim those are line noise in the middle of the thing being read: `ESC[0;32m` in front of
|
||||
* every green word. Stripping them all would be the other half-answer -- colour is often the whole
|
||||
* of what a diff, a test run or a linter is saying.
|
||||
* verbatim those are line noise in the middle of the thing being read. Stripping them all would be
|
||||
* the other half-answer -- colour is often the whole of what a diff or a test run is saying.
|
||||
*
|
||||
* So the sequences that decide how text *looks* become spans, and every other one is dropped.
|
||||
* Dropped rather than shown, because the rest move a cursor around a grid this is not: a transcript
|
||||
* is a scrolling document, and "go to column 40" has no meaning here that is better than nothing.
|
||||
* So the sequences that decide how text *looks* become spans, and every other one is dropped rather
|
||||
* than shown: the rest move a cursor around a grid this is not, and "go to column 40" has no
|
||||
* meaning in a scrolling document.
|
||||
*
|
||||
* A carriage return is honoured the way a terminal honours it: what was written since the last line
|
||||
* break is thrown away and the line starts again. That is what makes a progress bar show its final
|
||||
* state rather than every state it passed through, which was tens of lines run together.
|
||||
* state rather than every state it passed through.
|
||||
*
|
||||
* Not a composable, and the palette is a parameter: this can then be remembered against the text it
|
||||
* Not a composable, and the palette is a parameter, so this can be remembered against the text it
|
||||
* parsed rather than re-run on every recomposition of the card holding it.
|
||||
*/
|
||||
fun ansiStyled(text: String, palette: AnsiPalette): AnnotatedString {
|
||||
@@ -71,10 +69,9 @@ fun ansiStyled(text: String, palette: AnsiPalette): AnnotatedString {
|
||||
if (final == 'm') sgr = sgr.apply(params, palette)
|
||||
}
|
||||
}
|
||||
// A bare carriage return rewrites the line. One before a newline is the other half
|
||||
// of a Windows line ending: it rewrites nothing, and it is dropped rather than kept,
|
||||
// since that pair is one line break and the return itself would draw as a stray
|
||||
// control character.
|
||||
// A bare carriage return rewrites the line. One before a newline is the other half of a
|
||||
// Windows line ending: it rewrites nothing, and it is dropped rather than kept, since
|
||||
// that pair is one line break.
|
||||
c == '\r' && text.getOrNull(at + 1) != '\n' -> {
|
||||
flush()
|
||||
dropLine(runs)
|
||||
@@ -82,8 +79,8 @@ fun ansiStyled(text: String, palette: AnsiPalette): AnnotatedString {
|
||||
}
|
||||
c == '\r' -> at++
|
||||
// Everything printable, plus the two control characters that are layout rather than
|
||||
// terminal commands. A stray bell or backspace goes for the same reason a cursor
|
||||
// move does.
|
||||
// terminal commands. A stray bell or backspace goes for the same reason a cursor move
|
||||
// does.
|
||||
c >= ' ' || c == '\n' || c == '\t' -> {
|
||||
plain.append(c)
|
||||
at++
|
||||
@@ -129,9 +126,8 @@ private const val BELL = '\u0007'
|
||||
* Steps over the escape sequence starting at [at], reporting a CSI's parameters and final byte.
|
||||
*
|
||||
* One reader for every kind, because the point is to *leave* them all behind: a sequence this did
|
||||
* not recognise would otherwise have its body printed as ordinary text, which is worse than the
|
||||
* escape it was meant to remove. Three shapes -- the CSI (`ESC [ … letter`), the string escapes
|
||||
* (OSC, DCS, APC, PM) which run to a terminator, and the two-character ones.
|
||||
* not recognise would otherwise have its body printed as ordinary text. Three shapes -- the CSI
|
||||
* (`ESC [ … letter`), the string escapes which run to a terminator, and the two-character ones.
|
||||
*/
|
||||
private inline fun skipEscape(text: String, at: Int, onCsi: (String, Char) -> Unit): Int {
|
||||
val next = text.getOrNull(at + 1) ?: return at + 1
|
||||
@@ -140,9 +136,9 @@ private inline fun skipEscape(text: String, at: Int, onCsi: (String, Char) -> Un
|
||||
var end = at + 2
|
||||
while (end < text.length && text[end] !in CSI_FINAL) end++
|
||||
if (end >= text.length) {
|
||||
// Cut off mid-sequence, which is what a stream that has not finished arriving
|
||||
// looks like: drop the fragment rather than printing it, and the whole sequence
|
||||
// arrives with the next delta.
|
||||
// Cut off mid-sequence, which is what a stream that has not finished arriving looks
|
||||
// like: drop the fragment rather than printing it, and the whole sequence arrives
|
||||
// with the next delta.
|
||||
text.length
|
||||
} else {
|
||||
onCsi(text.substring(at + 2, end), text[end])
|
||||
|
||||
Reference in new issue
Block a user