Skip to content

Commit

Permalink
merge: Display emoji in Windows Terminal (#1117)
Browse files Browse the repository at this point in the history
Using jline dumb terminal
  • Loading branch information
ice1000 authored Jun 19, 2024
2 parents 3482274 + ce07540 commit 3031874
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package org.aya.cli.console;

import org.aya.pretty.printer.PrinterConfig;
import org.aya.repl.ReplUtil;
import org.aya.util.error.SourcePos;
import org.aya.util.prettier.PrettierOptions;
import org.aya.util.reporter.Problem;
Expand All @@ -27,7 +28,11 @@ public record AnsiReporter(
) implements Reporter {
@Contract(pure = true, value = "_, _, _ -> new")
public static @NotNull AnsiReporter stdio(boolean unicode, @NotNull PrettierOptions options, @NotNull Problem.Severity minimum) {
// AnsiConsole.systemInstall();
if (unicode) try {
var out = ReplUtil.jlineDumbTerminalWriter();
return new AnsiReporter(true, () -> true, () -> options, minimum, out, out);
} catch (Exception _) {
}
return new AnsiReporter(true, () -> unicode, () -> options, minimum,
System.out::println, System.err::println);
}
Expand Down
23 changes: 17 additions & 6 deletions cli-console/src/main/java/org/aya/cli/plct/PLCTReport.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Tesla (Yinsen) Zhang.
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.cli.plct;

Expand All @@ -9,6 +9,7 @@
import kala.tuple.Tuple2;
import org.aya.cli.console.MainArgs;
import org.aya.pretty.doc.Doc;
import org.aya.repl.ReplUtil;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;

Expand All @@ -21,6 +22,7 @@
import java.net.http.HttpResponse;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.function.Consumer;

public final class PLCTReport {
@NotNull
Expand All @@ -29,8 +31,17 @@ public final class PLCTReport {
Tuple.of("Aya VSCode", "aya-prover/aya-vscode"),
Tuple.of("Aya Intellij Plugin", "aya-prover/intellij-aya")
);
public static final @NotNull @Nls String SHRUG = "\ud83e\udd37";
public static final @NotNull @Nls String SHRUG = "🤷";
private final @NotNull HttpClient client = HttpClient.newBuilder().version(HttpClient.Version.HTTP_2).build();
private Consumer<String> out;

{
try {
out = ReplUtil.jlineDumbTerminalWriter();
} catch (Exception _) {
out = System.out::println;
}
}

private Doc pullRequest(GsonClasses.PR i) {
return Doc.sepNonEmpty(
Expand All @@ -52,15 +63,15 @@ private Doc pullRequest(GsonClasses.PR i) {

public int run(@NotNull MainArgs.PlctAction args) throws Exception {
if (!args.plctReport) {
System.out.println(SHRUG);
out.accept(SHRUG);
return 1;
}
Doc markdown;
LocalDateTime since;
if (args.reportSince > 0) {
since = LocalDate.now().minusDays(args.reportSince).atStartOfDay();
} else if (args.reportSince < 0) {
System.out.println(SHRUG);
out.accept(SHRUG);
return 1;
} else since = sinceDate().atStartOfDay();
if (args.repoName != null) {
Expand All @@ -71,7 +82,7 @@ public int run(@NotNull MainArgs.PlctAction args) throws Exception {
.view()
.prepended(Doc.plain("## The Aya Theorem Prover")));
}
System.out.println(markdown.debugRender());
out.accept(markdown.debugRender());
return 0;
}

Expand Down Expand Up @@ -104,7 +115,7 @@ public int run(@NotNull MainArgs.PlctAction args) throws Exception {
? LocalDate.of(year, month, 1)
// Generating the report at the start of next month -- collect last month
: month == 1 ? LocalDate.of(year - 1, 12, 1)
: LocalDate.of(year, month - 1, 1);
: LocalDate.of(year, month - 1, 1);
}

public static @NotNull ImmutableSeq<GsonClasses.PR> parse(@NotNull InputStream input) {
Expand Down
6 changes: 3 additions & 3 deletions cli-impl/src/main/java/org/aya/cli/single/CompilerFlags.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Tesla (Yinsen) Zhang.
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.cli.single;

Expand Down Expand Up @@ -54,8 +54,8 @@ public record PrettyInfo(
}

public record Message(
@NotNull String successNotion,
@NotNull String failNotion
@NotNull String successNotation,
@NotNull String failNotation
) {
public static final Message EMOJI = new Message("🎉", "🥲");
public static final Message ASCII = new Message("That looks right!", "Let's learn from that.");
Expand Down
4 changes: 2 additions & 2 deletions cli-impl/src/main/java/org/aya/cli/utils/CompilerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public static int catching(
if (flags.interruptedTrace()) e.printStackTrace();
}
if (reporter.noError()) {
reporter.reportString(flags.message().successNotion());
reporter.reportString(flags.message().successNotation());
return 0;
} else {
reporter.reportString(reporter.countToString());
reporter.reportString(flags.message().failNotion());
reporter.reportString(flags.message().failNotation());
return 1;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Tesla (Yinsen) Zhang.
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.pretty.backend.latex;

Expand Down Expand Up @@ -69,30 +69,30 @@ protected void renderStyleCommand(@NotNull Cursor cursor) {
Tuple.of("/\\", "\\land"),
Tuple.of("|", "\\mid"),
Tuple.of("=>", "\\Rightarrow"),
Tuple.of("\u2191", "\\uparrow"),
Tuple.of("", "\\uparrow"),
Tuple.of("->", "\\to"),
Tuple.of("_|_", "\\bot"),
Tuple.of("forall", "\\forall"),
Tuple.of("\u03A3", "\\Sigma"),
Tuple.of("\u2228", "\\lor"),
Tuple.of("\u2227", "\\land"),
Tuple.of("\u21D2", "\\Rightarrow"),
Tuple.of("\u2192", "\\to"),
Tuple.of("\u22A5", "\\bot"),
Tuple.of("\u2200", "\\forall"),
Tuple.of("Σ", "\\Sigma"),
Tuple.of("", "\\lor"),
Tuple.of("", "\\land"),
Tuple.of("", "\\Rightarrow"),
Tuple.of("", "\\to"),
Tuple.of("", "\\bot"),
Tuple.of("", "\\forall"),
Tuple.of("_", "\\_"),
Tuple.of("~", "\\neg"),
Tuple.of("**", "\\times"),
id("(|"), id("|)"),
Tuple.of("\u2987", "(|"),
Tuple.of("\u2988", "|)"),
Tuple.of("", "(|"),
Tuple.of("", "|)"),
id("[|"), id("|]"),
Tuple.of("\u27E6", "[|"),
Tuple.of("\u27E7", "|]"),
Tuple.of("", "[|"),
Tuple.of("", "|]"),
Tuple.of("{|", "\\{|"),
Tuple.of("|}", "|\\}"),
Tuple.of("\u2983", "\\{|"),
Tuple.of("\u2984", "|\\}"),
Tuple.of("", "\\{|"),
Tuple.of("", "|\\}"),
id(":"), id("."), id(":="), id("="),
id("("), id(")"),
Tuple.of("{", "\\{"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Tesla (Yinsen) Zhang.
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.pretty.backend.md;

Expand All @@ -19,8 +19,7 @@ public class DocMdPrinter extends DocHtmlPrinter<DocMdPrinter.Config> {
/** `Doc.plain("1. hello")` should not be rendered as a list, see MdStyleTest */
public static final Pattern MD_ESCAPE_FAKE_LIST = Pattern.compile("(^\\s*\\d+)\\.( |$)", Pattern.MULTILINE);

@Override protected void renderHeader(@NotNull Cursor cursor) {
}
@Override protected void renderHeader(@NotNull Cursor cursor) { }

@Override protected void renderFooter(@NotNull Cursor cursor) {
// put generated styles at the end of the file
Expand Down
4 changes: 2 additions & 2 deletions pretty/src/main/java/org/aya/pretty/backend/md/MdStyle.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2022 Tesla (Yinsen) Zhang.
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.pretty.backend.md;

Expand All @@ -15,5 +15,5 @@ enum GFM implements MdStyle {
return new Heading(level);
}

record Heading(int level) implements MdStyle {}
record Heading(int level) implements MdStyle { }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Tesla (Yinsen) Zhang.
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.pretty.backend.string;

Expand All @@ -23,7 +23,7 @@ public StyleToken(@NotNull String start, @NotNull String end, boolean visible) {
this(c -> c.content(start, visible), c -> c.content(end, visible));
}

public static final @NotNull StyleToken NULL = new StyleToken(c -> {}, c -> {});
public static final @NotNull StyleToken NULL = new StyleToken(_ -> { }, _ -> { });
}

@Override
Expand Down Expand Up @@ -110,7 +110,7 @@ public Delegate(@NotNull ClosingStylist delegate) {

@Override
protected @NotNull StyleToken formatLineThrough(@NotNull Style.LineThrough line, EnumSet<StringPrinter.Outer> outer) {
return delegate.formatLineThrough(line,outer);
return delegate.formatLineThrough(line, outer);
}

@Override protected @NotNull StyleToken formatColorHex(int rgb, boolean background) {
Expand Down
37 changes: 8 additions & 29 deletions pretty/src/main/java/org/aya/pretty/backend/string/Cursor.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2022 Tesla (Yinsen) Zhang.
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.pretty.backend.string;

Expand All @@ -11,21 +11,10 @@ public class Cursor {
private final StringBuilder builder = new StringBuilder();
private final StringPrinter<?> printer;

public Cursor(StringPrinter<?> printer) {
this.printer = printer;
}

public @NotNull CharSequence result() {
return builder;
}

public int getCursor() {
return cursor;
}

public int getNestLevel() {
return nestLevel;
}
public Cursor(StringPrinter<?> printer) { this.printer = printer; }
public @NotNull CharSequence result() { return builder; }
public int getCursor() { return cursor; }
public int getNestLevel() { return nestLevel; }

public void content(@NotNull CharSequence content, boolean visible) {
if (visible) visibleContent(content);
Expand Down Expand Up @@ -58,19 +47,9 @@ public void lineBreakWith(@NotNull CharSequence lineBreak) {
invisibleContent(lineBreak);
moveToNewLine();
}

public boolean isAtLineStart() {
return cursor == lineStartCursor;
}

public void moveToNewLine() {
cursor = lineStartCursor = 0;
}

public void moveForward(int count) {
cursor += Math.max(0, count);
}

public boolean isAtLineStart() { return cursor == lineStartCursor; }
public void moveToNewLine() { cursor = lineStartCursor = 0; }
public void moveForward(int count) { cursor += Math.max(0, count); }
public void nested(int nest, @NotNull Runnable r) {
nestLevel += nest;
r.run();
Expand Down
Loading

0 comments on commit 3031874

Please sign in to comment.