1 changed files with 0 additions and 50 deletions
@ -1,50 +0,0 @@ |
|||
package com.example.datacollect.view; |
|||
|
|||
import com.example.datacollect.model.Article; |
|||
import java.util.List; |
|||
import java.util.Scanner; |
|||
|
|||
public class ConsoleView { |
|||
private static final boolean DARK_MODE = true; |
|||
|
|||
private static final String ANSI_RESET = "\u001B[0m"; |
|||
private static final String ANSI_GREEN = DARK_MODE ? "\u001B[38;5;46m" : "\u001B[32m"; |
|||
private static final String ANSI_RED = DARK_MODE ? "\u001B[38;5;196m" : "\u001B[31m"; |
|||
private static final String ANSI_BLUE = DARK_MODE ? "\u001B[38;5;51m" : "\u001B[34m"; |
|||
private static final String ANSI_YELLOW = DARK_MODE ? "\u001B[38;5;226m" : "\u001B[33m"; |
|||
private static final String ANSI_WHITE = DARK_MODE ? "\u001B[38;5;255m" : "\u001B[37m"; |
|||
|
|||
private final Scanner scanner = new Scanner(System.in); |
|||
|
|||
public String readLine() { |
|||
System.out.print(DARK_MODE ? ANSI_WHITE + "> " + ANSI_RESET : "> "); |
|||
return scanner.nextLine(); |
|||
} |
|||
|
|||
public void printSuccess(String msg) { |
|||
System.out.println(ANSI_GREEN + msg + ANSI_RESET); |
|||
} |
|||
|
|||
public void printError(String msg) { |
|||
System.out.println(ANSI_RED + msg + ANSI_RESET); |
|||
} |
|||
|
|||
public void printInfo(String msg) { |
|||
System.out.println(ANSI_BLUE + msg + ANSI_RESET); |
|||
} |
|||
|
|||
public void printWarning(String msg) { |
|||
System.out.println(ANSI_YELLOW + msg + ANSI_RESET); |
|||
} |
|||
|
|||
public void display(List<Article> articles) { |
|||
if (articles.isEmpty()) { |
|||
printInfo("暂无文章,请先执行 crawl。"); |
|||
return; |
|||
} |
|||
for (int i = 0; i < articles.size(); i++) { |
|||
Article a = articles.get(i); |
|||
System.out.println((i + 1) + ". " + a.getTitle() + " | " + a.getUrl()); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue