Skip to content

improved readability of help messages #10304

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

Merged
merged 49 commits into from
Mar 5, 2021
Merged
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
b8f9bdb
improved readability of help messages
michelou Nov 13, 2020
5c29cfb
Merge remote-tracking branch 'upstream/master' into scala3-help
michelou Nov 13, 2020
093e5ca
Merge remote-tracking branch 'upstream/master' into scala3-help
michelou Nov 13, 2020
161b012
removed dependency on jline terminal
michelou Nov 13, 2020
80e673f
Merge remote-tracking branch 'upstream/master' into scala3-help
michelou Nov 14, 2020
33d8b63
added defaultPageWidth into ScalaSettings
michelou Nov 14, 2020
5a257df
Merge remote-tracking branch 'upstream/master' into scala3-help
michelou Nov 15, 2020
fa6cbeb
Merge remote-tracking branch 'upstream/master' into scala3-help
michelou Nov 17, 2020
30fca32
Merge remote-tracking branch 'upstream/master' into scala3-help
michelou Nov 19, 2020
686c0d1
Merge remote-tracking branch 'upstream/master' into scala3-help
michelou Nov 19, 2020
99c3f04
Merge remote-tracking branch 'upstream/master' into scala3-help
michelou Nov 21, 2020
3f97991
Merge remote-tracking branch 'upstream/master' into scala3-help
michelou Nov 23, 2020
4f825f6
sync with upstream
michelou Jan 30, 2021
27fecd7
Merge remote-tracking branch 'upstream/master' into scala3-help
michelou Jan 30, 2021
29c552d
improved readability of help messages
michelou Nov 13, 2020
73e482a
removed dependency on jline terminal
michelou Nov 13, 2020
c0e1d6c
rebased with upstream
michelou Feb 22, 2021
95229d4
Merge branch 'scala3-help' of https://github.com/michelou/dotty into …
michelou Feb 22, 2021
5c82e3e
Merge remote-tracking branch 'upstream/master' into HEAD
michelou Feb 23, 2021
0f7503c
sync with upstream
michelou Feb 25, 2021
5059475
Merge remote-tracking branch 'upstream/master' into HEAD
michelou Feb 26, 2021
5613181
Merge remote-tracking branch 'upstream/master' into HEAD
michelou Mar 1, 2021
8316dc4
Merge remote-tracking branch 'upstream/master' into scala3-help
michelou Mar 2, 2021
00bd288
sync with upstream, added tput
michelou Mar 2, 2021
19d7024
added missing source file
michelou Mar 2, 2021
6997b46
improved readability of help messages
michelou Nov 13, 2020
d330207
2nd attempt
michelou Mar 2, 2021
3839dd2
Merge remote-tracking branch 'upstream/master' into scala3-help
michelou Mar 2, 2021
3598d66
sync with upstream
michelou Mar 3, 2021
056f47a
Merge remote-tracking branch 'upstream/master' into scala3-help
michelou Mar 3, 2021
a957a51
sync with upstream
michelou Mar 4, 2021
3495899
Merge remote-tracking branch 'upstream/master' into scala3-help
michelou Mar 4, 2021
b9887ff
Merge remote-tracking branch 'upstream/master' into scala3-help
michelou Mar 4, 2021
abf5a9f
Merge remote-tracking branch 'upstream/master' into scala3-help
michelou Mar 4, 2021
9e5f044
Merge remote-tracking branch 'upstream/master' into scala3-help
michelou Mar 4, 2021
9ae830a
improved readability of help messages
michelou Nov 13, 2020
f714e36
removed dependency on jline terminal
michelou Nov 13, 2020
40156d5
sync with upstream
michelou Mar 4, 2021
5b2970c
improved readability of help messages
michelou Nov 13, 2020
4ef48a9
removed dependency on jline terminal
michelou Nov 13, 2020
5148a33
added defaultPageWidth into ScalaSettings
michelou Nov 14, 2020
6c38e39
sync with upstream, added tput
michelou Mar 2, 2021
49306d3
improved readability of help messages
michelou Nov 13, 2020
c743126
2nd attempt
michelou Mar 2, 2021
8f73dae
sync with upstream
michelou Mar 4, 2021
270fe25
Bring community build submodules up to date
griggt Mar 4, 2021
1c03961
dist/bin/*.bat belong to another branch
michelou Mar 5, 2021
640ed97
Merge branch 'scala3-help' of https://github.com/michelou/dotty into …
michelou Mar 5, 2021
063e09a
Merge remote-tracking branch 'upstream/master' into scala3-help
michelou Mar 5, 2021
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
30 changes: 15 additions & 15 deletions compiler/src/dotty/tools/dotc/config/CompilerCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package config

import java.nio.file.{Files, Paths}

import org.jline.terminal.TerminalBuilder

import Settings._
import core.Contexts._
import Properties._
Expand Down Expand Up @@ -69,14 +67,22 @@ object CompilerCommand {
def checkUsage(summary: ArgsSummary, sourcesRequired: Boolean)(using Context): List[String] = {
val settings = ctx.settings

/** Creates a help message for a subset of options based on cond;
* terminalWidth = 0 means no terminal is available.
*/
def availableOptionsMsg(cond: Setting[?] => Boolean, terminalWidth: Int = 0): String = {
/** Creates a help message for a subset of options based on cond */
def availableOptionsMsg(cond: Setting[?] => Boolean): String = {
val ss = (settings.allSettings filter cond).toList sortBy (_.name)
val maxNameWidth = 30
val nameWidths = ss.map(_.name.length).partition(_ < maxNameWidth)._1
val width = if nameWidths.nonEmpty then nameWidths.max else maxNameWidth
val width = if nameWidths.nonEmpty then nameWidths.max else maxNameWidth
val terminalWidth =
val pageWidth = settings.pageWidth.value
val columnsVar = System.getenv("COLUMNS")
if columnsVar != null then columnsVar.toInt
else if Properties.isWin then
val ansiconVar = System.getenv("ANSICON") // eg. "142x32766 (142x26)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking these environment variables seems like a good idea, but instead of doing it here, we could use them to set a default value for the pagewidth setting instead of 80, that way we'll use them in other situations where we're printing things: https://github.com/lampepfl/dotty/blob/6b9796c38c37957c6a6dba387c4a820b06976356/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala#L44

if ansiconVar != null && ansiconVar.matches("[0-9]+x.*") then
ansiconVar.substring(0, ansiconVar.indexOf("x")).toInt
else pageWidth
else pageWidth
val (nameWidth, descriptionWidth) = {
val w1 =
if width < maxNameWidth then width
Expand Down Expand Up @@ -124,14 +130,8 @@ object CompilerCommand {
Some(explainAdvanced) filter (_ => shouldExplain),
Some(label + " options include:")
).flatten mkString "\n"
try
// Use terminal width if terminal is available (see repl.JLineTerminal)
val terminal = TerminalBuilder.builder().dumb(false).build()
val usageMsg = prefix + "\n" + availableOptionsMsg(cond, terminal.getWidth)
terminal.close()
usageMsg
catch _ =>
prefix + "\n" + availableOptionsMsg(cond)

prefix + "\n" + availableOptionsMsg(cond)
}

def isStandard(s: Setting[?]): Boolean = !isAdvanced(s) && !isPrivate(s)
Expand Down