1 changed files with 0 additions and 68 deletions
@ -1,68 +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_THEME = true; |
|
||||
|
|
||||
private static final String ANSI_RESET = "\u001B[0m"; |
|
||||
private static final String ANSI_GREEN = "\u001B[32m"; |
|
||||
private static final String ANSI_RED = "\u001B[31m"; |
|
||||
private static final String ANSI_BLUE = "\u001B[34m"; |
|
||||
|
|
||||
private static final String ANSI_CYAN = "\u001B[36m"; |
|
||||
private static final String ANSI_YELLOW = "\u001B[33m"; |
|
||||
private static final String ANSI_WHITE = "\u001B[37m"; |
|
||||
|
|
||||
private final Scanner scanner = new Scanner(System.in); |
|
||||
|
|
||||
public String readLine() { |
|
||||
if (DARK_THEME) { |
|
||||
System.out.print(ANSI_WHITE + "> " + ANSI_RESET); |
|
||||
} else { |
|
||||
System.out.print("> "); |
|
||||
} |
|
||||
return scanner.nextLine(); |
|
||||
} |
|
||||
|
|
||||
public void printSuccess(String msg) { |
|
||||
if (DARK_THEME) { |
|
||||
System.out.println(ANSI_GREEN + msg + ANSI_RESET); |
|
||||
} else { |
|
||||
System.out.println(ANSI_GREEN + msg + ANSI_RESET); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public void printError(String msg) { |
|
||||
if (DARK_THEME) { |
|
||||
System.out.println(ANSI_RED + msg + ANSI_RESET); |
|
||||
} else { |
|
||||
System.out.println(ANSI_RED + msg + ANSI_RESET); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public void printInfo(String msg) { |
|
||||
if (DARK_THEME) { |
|
||||
System.out.println(ANSI_CYAN + msg + ANSI_RESET); |
|
||||
} else { |
|
||||
System.out.println(ANSI_BLUE + 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); |
|
||||
if (DARK_THEME) { |
|
||||
System.out.println(ANSI_WHITE + (i + 1) + ". " + a.getTitle() + " | " + a.getUrl() + ANSI_RESET); |
|
||||
} else { |
|
||||
System.out.println((i + 1) + ". " + a.getTitle() + " | " + a.getUrl()); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue