mirror of
				https://github.com/JakeWharton/mosaic.git
				synced 2025-11-04 06:32:26 +08:00 
			
		
		
		
	Share constants for ANSI control codes
This commit is contained in:
		
				
					committed by
					
						
						Jake Wharton
					
				
			
			
				
	
			
			
			
						parent
						
							3c18954fb0
						
					
				
				
					commit
					66eca84c5d
				
			@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					package com.jakewharton.mosaic
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					internal const val clearLine = "\u001B[K"
 | 
				
			||||||
 | 
					internal const val cursorUp = "\u001B[F"
 | 
				
			||||||
@ -47,14 +47,14 @@ internal class AnsiRendering : Rendering {
 | 
				
			|||||||
			clear()
 | 
								clear()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			repeat(lastHeight) {
 | 
								repeat(lastHeight) {
 | 
				
			||||||
				append("\u001B[F") // Cursor up line.
 | 
									append(cursorUp)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			val staticLines = statics.flatMap { it.render().split("\n") }
 | 
								val staticLines = statics.flatMap { it.render().split("\n") }
 | 
				
			||||||
			val lines = canvas.render().split("\n")
 | 
								val lines = canvas.render().split("\n")
 | 
				
			||||||
			for (line in staticLines + lines) {
 | 
								for (line in staticLines + lines) {
 | 
				
			||||||
				append(line)
 | 
									append(line)
 | 
				
			||||||
				append("\u001B[K") // Clear rest of line.
 | 
									append(clearLine)
 | 
				
			||||||
				append('\n')
 | 
									append('\n')
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -64,12 +64,12 @@ internal class AnsiRendering : Rendering {
 | 
				
			|||||||
				if (i > 0) {
 | 
									if (i > 0) {
 | 
				
			||||||
					append('\n')
 | 
										append('\n')
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				append("\u001B[K") // Clear line.
 | 
									append(clearLine)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// Move cursor back up to end of the new output.
 | 
								// Move cursor back up to end of the new output.
 | 
				
			||||||
			repeat(extraLines - 1) {
 | 
								repeat(extraLines - 1) {
 | 
				
			||||||
				append("\u001B[F") // Cursor up line.
 | 
									append(cursorUp)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			lastHeight = lines.size
 | 
								lastHeight = lines.size
 | 
				
			||||||
 | 
				
			|||||||
@ -16,8 +16,8 @@ class AnsiRenderingTest {
 | 
				
			|||||||
		// TODO We should not draw trailing whitespace.
 | 
							// TODO We should not draw trailing whitespace.
 | 
				
			||||||
		assertEquals(
 | 
							assertEquals(
 | 
				
			||||||
			"""
 | 
								"""
 | 
				
			||||||
			|Hello $esc[K
 | 
								|Hello $clearLine
 | 
				
			||||||
			|World!$esc[K
 | 
								|World!$clearLine
 | 
				
			||||||
			|""".trimMargin(),
 | 
								|""".trimMargin(),
 | 
				
			||||||
			rendering.render(helloCanvas).toString(),
 | 
								rendering.render(helloCanvas).toString(),
 | 
				
			||||||
		)
 | 
							)
 | 
				
			||||||
 | 
				
			|||||||
@ -13,9 +13,9 @@ class MosaicTest {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		assertEquals("""
 | 
							assertEquals("""
 | 
				
			||||||
			|One  $esc[K
 | 
								|One  $clearLine
 | 
				
			||||||
			|Two  $esc[K
 | 
								|Two  $clearLine
 | 
				
			||||||
			|Three$esc[K
 | 
								|Three$clearLine
 | 
				
			||||||
			|""".trimMargin(), actual)
 | 
								|""".trimMargin(), actual)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,3 +0,0 @@
 | 
				
			|||||||
package com.jakewharton.mosaic
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
internal const val esc = "\u001B"
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user