+
Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.
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
4 changes: 2 additions & 2 deletions crates/rome_cli/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ pub(crate) fn execute_mode(
})?;
let printed = workspace.format_file(FormatFileParams { path: rome_path })?;

console.log(markup! {
console.append(markup! {
{printed.as_code()}
});
} else {
console.log(markup! {
console.append(markup! {
{content}
});
console.error(markup!{
Expand Down
42 changes: 39 additions & 3 deletions crates/rome_console/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ pub enum LogLevel {
/// Generic abstraction over printing markup and diagnostics to an output,
/// which can be a terminal, a file, a memory buffer ...
pub trait Console: Send + Sync + RefUnwindSafe {
/// Prints a message (formatted using [markup!]) to the console
/// Prints a message (formatted using [markup!]) to the console.
///
/// It adds a new line at the end.
fn println(&mut self, level: LogLevel, args: Markup);

/// Prints a message (formatted using [markup!]) to the console.
fn print(&mut self, level: LogLevel, args: Markup);

/// It reads from a source, and if this source contains something, it's converted into a [String]
Expand All @@ -40,15 +45,26 @@ pub trait ConsoleExt: Console {
fn error(&mut self, args: Markup);

/// Prints a piece of markup with level [LogLevel::Log]
///
/// Logs a message, adds a new line at the end.
fn log(&mut self, args: Markup);

/// Prints a piece of markup with level [LogLevel::Log]
///
/// It doesn't add any line
fn append(&mut self, args: Markup);
}

impl<T: Console + ?Sized> ConsoleExt for T {
fn error(&mut self, args: Markup) {
self.print(LogLevel::Error, args);
self.println(LogLevel::Error, args);
}

fn log(&mut self, args: Markup) {
self.println(LogLevel::Log, args);
}

fn append(&mut self, args: Markup) {
self.print(LogLevel::Log, args);
}
}
Expand Down Expand Up @@ -122,7 +138,7 @@ impl Default for EnvConsole {
}

impl Console for EnvConsole {
fn print(&mut self, level: LogLevel, args: Markup) {
fn println(&mut self, level: LogLevel, args: Markup) {
let mut out = match level {
LogLevel::Error => self.err.lock(),
LogLevel::Log => self.out.lock(),
Expand All @@ -135,6 +151,19 @@ impl Console for EnvConsole {
writeln!(out).unwrap();
}

fn print(&mut self, level: LogLevel, args: Markup) {
let mut out = match level {
LogLevel::Error => self.err.lock(),
LogLevel::Log => self.out.lock(),
};

fmt::Formatter::new(&mut Termcolor(&mut out))
.write_markup(args)
.unwrap();

write!(out, "").unwrap();
}

fn read(&mut self) -> Option<String> {
// Here we check if stdin is redirected. If not, we bail.
//
Expand Down Expand Up @@ -170,6 +199,13 @@ pub struct Message {
}

impl Console for BufferConsole {
fn println(&mut self, level: LogLevel, args: Markup) {
self.out_buffer.push(Message {
level,
content: args.to_owned(),
});
}

fn print(&mut self, level: LogLevel, args: Markup) {
self.out_buffer.push(Message {
level,
Expand Down
4 changes: 2 additions & 2 deletions xtask/lintdoc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ fn assert_lint(
if all_diagnostics.len() > 1 {
let mut console = rome_console::EnvConsole::default();
for diag in all_diagnostics.iter() {
console.print(
console.println(
rome_console::LogLevel::Error,
markup! {
{PrintDiagnostic::verbose(diag)}
Expand All @@ -500,7 +500,7 @@ fn assert_lint(
// Print all diagnostics to help the user
let mut console = rome_console::EnvConsole::default();
for diag in all_diagnostics.iter() {
console.print(
console.println(
rome_console::LogLevel::Error,
markup! {
{PrintDiagnostic::verbose(diag)}
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载