Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecations #229

Merged
merged 4 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@
- **Breaking Change** `TerminalInterface.info` is now a method with parameters instead of a property.
- **Breaking Change** Moved `Markdown` widget to separate `mordant-markdown` module, which is not included by default. If you use markdown rendering, you need to add that module to you dependencies.
- In raw mode on POSIX systems, pressing the escape key once will now immediately return an `Escape` event. [(#193)](https://github.com/ajalt/mordant/issues/193)
- Renamed `TerminalInfo.crClearsLine` to `supportsAnsiCursor`
- Combined all `ColumnWidth` subclasses into a single class with factory methods. If you were using `ColumnWidth.Custom`, you should now use the `ColumnWidth` constructor.
- The following `Terminal` methods are now extensions: `prompt()`, `info()`, `danger()`, `warning()`, `success()`, `muted()`
- Renamed `Terminal.info` property to `Terminal.terminalInfo`

### Removed
- Removed constructor overloads for `Terminal`. There is now one constructor with all default parameters.
- Removed `Terminal.colors`. All colors rendered with the terminal are now automatically downsampled.
- Removed previously deprecated methods.

### Fixed
- Fixed ConcurrentModificationException from progress bars when updated under very high concurrency [(#204)](https://github.com/ajalt/mordant/issues/204)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Markdown(
private var document: Widget? = null
private fun document(t: Terminal): Widget {
if (document == null) {
document = MarkdownRenderer(markdown, t.theme, showHtml, hyperlinks ?: t.info.ansiHyperLinks).render()
document = MarkdownRenderer(markdown, t.theme, showHtml, hyperlinks ?: t.terminalInfo.ansiHyperLinks).render()
}
return document!!
}
Expand Down
196 changes: 40 additions & 156 deletions mordant/api/mordant.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import com.github.ajalt.mordant.widgets.progress.progressBarLayout
* cause garbled output, so usage of this class should be serialized.
*/
abstract class Animation<T>(
@Deprecated("This parameter is ignored; animations never print a trailing linebreak.")
private val trailingLinebreak: Boolean = true,
val terminal: Terminal,
) : StoppableAnimation {
private data class State(
Expand Down Expand Up @@ -150,7 +148,7 @@ abstract class Animation<T>(
text = terminal.render(rendered)
)
}
if (!old.interceptorInstalled && terminal.info.outputInteractive) {
if (!old.interceptorInstalled && terminal.terminalInfo.outputInteractive) {
terminal.addInterceptor(interceptor)
}
// Print an empty widget to trigger our interceptor, which will add the rendered text
Expand All @@ -171,7 +169,7 @@ abstract class Animation<T>(
startOfLine()
if (CR_IMPLIES_LF) up(1)

if (terminal.info.crClearsLine) {
if (terminal.terminalInfo.supportsAnsiCursor) {
// IntelliJ doesn't support cursor moves, so this is all we can do
return@getMoves
}
Expand Down Expand Up @@ -208,10 +206,9 @@ abstract class Animation<T>(
* @see Animation
*/
inline fun <T> Terminal.animation(
trailingLinebreak: Boolean = true,
crossinline draw: (T) -> Widget,
): Animation<T> {
return object : Animation<T>(trailingLinebreak, this) {
return object : Animation<T>(this) {
override fun renderData(data: T): Widget = draw(data)
}
}
Expand All @@ -226,10 +223,9 @@ inline fun <T> Terminal.textAnimation(
overflowWrap: OverflowWrap = OverflowWrap.NORMAL,
width: Int? = null,
tabWidth: Int? = null,
trailingLinebreak: Boolean = true,
crossinline draw: (T) -> String,
): Animation<T> {
return object : Animation<T>(trailingLinebreak, this) {
return object : Animation<T>(this) {
override fun renderData(data: T): Widget {
return Text(draw(data), whitespace, align, overflowWrap, width, tabWidth)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import kotlin.time.TimeSource
* @throws RuntimeException if the terminal is not interactive or raw mode cannot be entered.
*/
fun Terminal.enterRawMode(mouseTracking: MouseTracking = MouseTracking.Off): RawModeScope {
if (!info.inputInteractive) {
if (!terminalInfo.inputInteractive) {
throw IllegalStateException("Cannot enter raw mode on a non-interactive terminal")
}
return RawModeScope(this, terminalInterface.enterRawMode(mouseTracking), mouseTracking)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,4 @@ enum class Borders(
LEFT_TOP_BOTTOM(left = true, top = true, right = false, bottom = true),
LEFT_TOP_RIGHT(left = true, top = true, right = true, bottom = false),
ALL(left = true, top = true, right = true, bottom = true),

@Suppress("unused")
@Deprecated("Use TOP_BOTTOM", replaceWith = ReplaceWith("TOP_BOTTOM"))
TOM_BOTTOM(left = false, top = true, right = false, bottom = true),
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ internal class TableImpl(
val borderStyle: TextStyle,
val headerRowCount: Int,
val footerRowCount: Int,
val columnWidths: List<ColumnWidth.Custom>,
val columnWidths: List<ColumnWidth>,
val tableBorders: Borders?,
val addPaddingWidthToFixedWidth: Boolean,
) : Table() {
Expand Down
174 changes: 67 additions & 107 deletions mordant/src/commonMain/kotlin/com/github/ajalt/mordant/table/TableDsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package com.github.ajalt.mordant.table

import com.github.ajalt.colormath.Color
import com.github.ajalt.mordant.rendering.*
import com.github.ajalt.mordant.table.ColumnWidth.Companion.Auto
import com.github.ajalt.mordant.table.ColumnWidth.Companion.Expand
import com.github.ajalt.mordant.table.ColumnWidth.Companion.Fixed
import com.github.ajalt.mordant.widgets.Caption
import com.github.ajalt.mordant.widgets.Padding
import com.github.ajalt.mordant.widgets.withPadding
Expand Down Expand Up @@ -38,9 +41,6 @@ interface CellStyleBuilderBase {
}

interface CellStyleBuilder : CellStyleBuilderBase {
@Deprecated("borders has been renamed to cellBorders", replaceWith = ReplaceWith("cellBorders"))
var borders: Borders?

/**
* Borders around each individual cell.
*
Expand Down Expand Up @@ -73,81 +73,80 @@ interface CellStyleBuilder : CellStyleBuilderBase {
}
}

sealed class ColumnWidth {
// TODO(3.0): this is a separate class for backwards compatibility; make other ColumnWidth subclasses
// instances of this in 3.0
/**
* Configuration for how a column should be sized in a table.
*/
data class ColumnWidth(
// TODO(3.0): add a `minimumWidth?` field and use it for progress cells like timeRemaining
/**
* A column width with custom behavior.
* The priority of the column when allocating available width.
*
* Available width is allocated to columns in decreasing order of priority.
*
* - [Fixed] columns have a priority of 3.
* - [Auto] columns have a priority of 2.
* - [Expand] columns have a priority of 1.
*/
data class Custom(
/** The fixed width of the column, or `null` if the width should be computed automatically */
val width: Int?,
/**
* The weight of the column when expanding, or `null` if the column should not expand.
*
* If there are multiple expanding columns with the same [priority], the available width
* will be divided among them proportional to their weights.
*/
val expandWeight: Float?,
/**
* The priority of the column when allocating available width.
*
* Available width is allocated to columns in decreasing order of priority.
*
* - [Fixed] columns have a priority of 3.
* - [Auto] columns have a priority of 2.
* - [Expand] columns have a priority of 1.
*/
val priority: Int,
) : ColumnWidth() {
init {
require(width == null || width > 0) { "width must be greater than zero" }
require(expandWeight == null || expandWeight > 0f) {
"expandWeight must be greater than zero"
}
require(width == null || expandWeight == null) {
"Cannot set both width and expandWeight"
}
val priority: Int,
/**
* The fixed width of the column, or `null` if the width should be computed automatically
*/
val width: Int? = null,
/**
* The weight of the column when expanding, or `null` if the column should not expand.
*
* If there are multiple expanding columns with the same [priority], the available width
* will be divided among them proportional to their weights.
*/
val expandWeight: Float? = null,
) {
init {
require(width == null || width > 0) { "width must be greater than zero" }
require(expandWeight == null || expandWeight > 0f) {
"expandWeight must be greater than zero"
}
require(width == null || expandWeight == null) {
"Cannot set both width and expandWeight"
}
}

override fun toString(): String {
return when {
isAuto -> "Auto"
isExpand -> "Expand($expandWeight)"
isFixed -> "Fixed($width)"
else -> "Custom(width=$width, expandWeight=$expandWeight, priority=$priority)"
}
override fun toString(): String {
return when {
isAuto -> "Auto"
isExpand -> "Expand($expandWeight)"
isFixed -> "Fixed($width)"
else -> "Custom(width=$width, expandWeight=$expandWeight, priority=$priority)"
}
}

/** The column will fit to the size of its content */
data object Auto : ColumnWidth()
@Suppress("FunctionName")
companion object {

/**
* The column will have a fixed [width].
*
* The width includes padding, so increasing horizontal padding of a fixed column will decrease content width rather
* than expand the column.
*/
class Fixed(val width: Int) : ColumnWidth() {
init {
/** The column will fit to the size of its content */
val Auto = ColumnWidth(2)

/**
* The column will have a fixed [width].
*
* The width includes padding, so increasing horizontal padding of a fixed column will decrease content width rather
* than expand the column.
*/
fun Fixed(width: Int): ColumnWidth {
require(width > 0) { "width must be greater than zero" }
return ColumnWidth(3, width)
}
}

/**
* The column will expand to fill the available terminal width.
*
* If there are multiple expanding columns, the available width will be divided among them
* proportional to their [weight]s.
*/
class Expand(val weight: Float = 1f) : ColumnWidth() {
init {
require(weight > 0) { "weight must be greater than zero" }
/**
* The column will expand to fill the available terminal width.
*
* If there are multiple expanding columns, the available width will be divided among them
* proportional to their [weight]s.
*/
fun Expand(weight: Number = 1f): ColumnWidth {
val w = weight.toFloat()
require(w > 0) { "weight must be greater than zero" }
return ColumnWidth(1, null, w)
}

constructor(weight: Number) : this(weight.toFloat())
}
}

Expand Down Expand Up @@ -211,9 +210,6 @@ interface TableBuilder : CellStyleBuilder, ColumnHolderBuilder {

/** Configure the footer section. */
fun footer(init: SectionBuilder.() -> Unit)

@Deprecated("`outerBorder=false` has been replaced with `tableBorders=Borders.NONE`")
var outerBorder: Boolean
}

@MordantDsl
Expand Down Expand Up @@ -375,47 +371,11 @@ fun verticalLayout(init: VerticalLayoutBuilder.() -> Unit): Widget {
return VerticalLayoutBuilderInstance().apply(init).build()
}

@Deprecated(
"row is renamed to horizontalLayout",
replaceWith = ReplaceWith("horizontalLayout(init)")
)
fun row(padding: Int = 0, init: HorizontalLayoutBuilder.() -> Unit): Widget {
return horizontalLayout {
spacing = padding
init()
}
}

@Deprecated(
"column is renamed to verticalLayout",
replaceWith = ReplaceWith("verticalLayout(init)")
)
fun column(padding: Int = 0, init: VerticalLayoutBuilder.() -> Unit): Widget = verticalLayout {
init()
this.spacing = padding
}

internal fun ColumnWidth?.toCustom(): ColumnWidth.Custom {
return when (this) {
is ColumnWidth.Expand -> ColumnWidth.Custom(null, weight, 1)
null, is ColumnWidth.Auto -> ColumnWidth.Custom(null, null, 2)
is ColumnWidth.Fixed -> ColumnWidth.Custom(width, null, 3)
is ColumnWidth.Custom -> this
}
}

internal val ColumnWidth.isAuto: Boolean
get() {
return this is ColumnWidth.Auto ||
this is ColumnWidth.Custom && this.width == null && this.expandWeight == null
}
get() = this.width == null && this.expandWeight == null

internal val ColumnWidth.isExpand: Boolean
get() {
return this is ColumnWidth.Expand || this is ColumnWidth.Custom && this.expandWeight != null
}
get() = this.expandWeight != null

internal val ColumnWidth.isFixed: Boolean
get() {
return this is ColumnWidth.Fixed || this is ColumnWidth.Custom && this.width != null
}
get() = this.width != null
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ private class CellStyleBuilderMixin : CellStyleBuilder {
override var align: TextAlign? = null
override var verticalAlign: VerticalAlign? = null
override var overflowWrap: OverflowWrap? = null

@Deprecated("borders has been renamed to cellBorders", replaceWith = ReplaceWith("cellBorders"))
override var borders: Borders?
get() = cellBorders
set(value) {
cellBorders = value
}
}


Expand All @@ -44,13 +37,6 @@ internal class TableBuilderInstance : TableBuilder, CellStyleBuilder by CellStyl
var captionBottom: Widget? = null
private set

@Deprecated("`outerBorder=false` has been replaced with `tableBorders=Borders.NONE`")
override var outerBorder: Boolean
get() = tableBorders != Borders.ALL
set(value) {
tableBorders = if (value) Borders.ALL else Borders.NONE
}

override fun captionTop(widget: Widget) {
captionTop = widget
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.ajalt.mordant.table

import com.github.ajalt.mordant.rendering.*
import com.github.ajalt.mordant.table.ColumnWidth.Companion.Auto
import com.github.ajalt.mordant.widgets.EmptyWidget
import com.github.ajalt.mordant.widgets.Padding
import com.github.ajalt.mordant.widgets.Text
Expand Down Expand Up @@ -43,7 +44,7 @@ internal class TableLayout(private val table: TableBuilderInstance) {
val columnCount = rows.maxOf { it.size }

val columnWidths = List(columnCount) { i ->
table.columns[i]?.width.toCustom()
table.columns[i]?.width ?: Auto
}
return TableImpl(
rows = rows,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.github.ajalt.mordant.internal.DEFAULT_STYLE
import com.github.ajalt.mordant.internal.EMPTY_LINE
import com.github.ajalt.mordant.rendering.*
import com.github.ajalt.mordant.rendering.TextAlign.NONE
import com.github.ajalt.mordant.table.ColumnWidth.Companion.Auto
import com.github.ajalt.mordant.terminal.Terminal

private class VerticalLayoutCell(
Expand Down Expand Up @@ -55,7 +56,7 @@ internal class VerticalLayout private constructor(

override fun render(t: Terminal, width: Int): Lines {
val renderWidth = when {
columnWidth is ColumnWidth.Expand -> width
columnWidth.isExpand -> width
hasAlignedCells -> measure(t, width).max
else -> width
}.coerceAtMost(width)
Expand All @@ -68,7 +69,7 @@ internal class VerticalLayout private constructor(
if (i > 0) repeat(spacing) { lines += spacingLine }
var rendered = cell.content.render(t, renderWidth).withStyle(cell.style)

val w = columnWidth.toCustom()
val w = columnWidth
rendered = when {
w.expandWeight != null -> rendered.setSize(width, textAlign = cell.textAlign)
w.width != null -> rendered.setSize(w.width, textAlign = cell.textAlign)
Expand Down
Loading