ballista-cli 55.0.0

Command Line Client for Ballista distributed query engine.
Documentation
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

//! # Ballista Web TUI application
//!
//! By using [`Ratzilla`](https://github.com/ratatui/ratzilla) the terminal user interface (TUI)
//! application is built as a web application (a WASM32 module).
//!
//! ## Running the application
//!
//! Prerequisites:
//!
//! ```text
//! cargo binstall trunk
//! ```
//!
//! ### Local
//!
//! For local development, run the following command:
//! ```text
//! trunk serve --no-default-features --features web
//! ```
//! Then open [http://localhost:8080](http://localhost:8080) in your browser.
//!
//! ### Production
//!
//! To build the application for production, run the following command:
//! ```text
//! trunk build --cargo-profile release --minify --locked \
//!             --no-default-features --features web
//! ```
//!
//! See [`Trunk.toml`](https://github.com/apache/datafusion-ballista/blob/main/ballista-cli/Trunk.toml)
//! for the build configuration.

#![cfg(feature = "web")]

use tracing_subscriber::fmt::format::Pretty;
use tracing_subscriber::prelude::*;
use tracing_web::{MakeWebConsoleWriter, performance_layer};
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::spawn_local;

/// WASM entry point. Registered as the `start` function so the browser calls it
/// automatically when the WASM module is loaded.
#[wasm_bindgen(start)]
pub fn wasm_start() {
    console_error_panic_hook::set_once();
    initialize_logging();

    spawn_local(async move {
        tracing::info!("Starting the Ballista WASM application");
        if let Err(e) = crate::tui::main().await {
            // unwrap_throw produces a JS exception visible in the browser console
            wasm_bindgen::throw_str(&format!("Ballista TUI failed to start: {e}"));
        }
    });
}

fn initialize_logging() {
    let fmt_layer = tracing_subscriber::fmt::layer()
        .with_ansi(false) // No ANSI colors in browser console
        .without_time() // std::time is not available in browsers
        .with_writer(MakeWebConsoleWriter::new()); // write events to the console

    let perf_layer = performance_layer().with_details_from_fields(Pretty::default());

    tracing_subscriber::registry()
        .with(fmt_layer)
        .with(perf_layer)
        .init(); // Install these as subscribers to tracing events

    tracing::info!("WASM app initialized");
}