@bobfrankston/msger

中文文档
0.1.436发布于 2026/11/07ISCTypeScriptES Module近 30 天下载 4103

快速, 轻量级, 跨平台的信息框 - Rust 动力替代 msgview

中文使用文档
文档目录40 节
  1. 快速链接
  2. 安装
  3. 基本实例
  4. 无头模式( E) -noshow )——以WebView为CSS/JS引擎
  5. 渲染模式( E) -render )——抓取页面到图像
  6. JSON 配置文件
  7. 完整的JSON结构
  8. 实地参考
  9. JSON 实例
  10. CLI 选项参考
  11. 快速启动
  12. 程序关闭 API (New!)
  13. API 函数
  14. showMessageBox(options: MessageBoxOptions): Promise<Message…
  15. API 示例
  16. 简单确认对话框
  17. 输入对话框
  18. HTML 内容
  19. ANSI 颜色代码
  20. 显示网页
  21. 自动关闭超时
  22. HTML 窗体
  23. 窗口定位
  24. 总是在顶部缩放( Z)
  25. 自动缩放窗口
  26. 已调试的 URL 浏览器
  27. 全屏模式
  28. 特征
  29. 为什么是Msger?
  30. msg 对 msgview 编辑器
  31. 何时使用 msger( 此软件包)
  32. 何时使用 msgview
  33. 窗口。 msgapi
  34. 重要说明
  35. 任务栏图标
  36. 警卫
  37. mSG 爪哇脚本 API
  38. 对于开发者
  39. 许可证
  40. 作者

@bobfrankston/邮件

用于Node.js应用的快速,轻量级信息箱.

以简单的 JavaScript API 显示本地信件框、对话框和 HTML 内容 。 作品有Windows,Linux(x64)和Linux(ARM64/Raspberry Pi).

安装

npm install @bobfrankston/msger

用于全球CLI:

npm install -g @bobfrankston/msger

支持的平台:

  • 视窗 (x64)
  • Linux (x64) (英语)
  • Linux (ARM64 / Raspberry Pi) (韩语)

命令行使用量

这个 msger 命令行工具提供了从 shell 脚本,分批文件,或终端显示消息框的快取方式.

基本实例

# Simple message
msger -message "Hello, World!"
msger Hello World  # shorthand - words become message

# With HTML content
msger -html "<h1>Welcome!</h1><p>This is <strong>HTML</strong></p>"

# Colored text with inline styles
msger -html "<span style='color:red;background-color:yellow'>Alert!</span>"

# Load a URL (web page, local file, or a directory's index.html)
msger -url "https://example.com"
msger -url "file:///path/to/page.html"
msger -url ./site          # serves ./site/index.html and its sibling assets

# Render a local markdown file — use the mdview wrapper (msger doesn't auto-render .md)
mdview todo.md

# Display arbitrary HTML as a complete page (no template, no buttons) — used by mdview
msger -raw -html "<!doctype html><html>...</html>"

# Load URL with hash fragment
msger -url "https://example.com" -hash section1
msger -url "https://example.com" -hash "#intro"

# With input field and placeholder
msger -message "Enter your name:" -input "Your name here" -default "John"

# Custom buttons
msger -message "Save changes?" -buttons Yes No Cancel

# With custom size and position
msger -message "Hello" -size 800,600 -pos 100,100

# Always on top with zoom
msger -message "Important!" -ontop -zoom 150

# Detached URL browser (stays open after script exits)
msger -url "https://example.com" -detach

# Fullscreen mode
msger -fullscreen -url "https://example.com"

# Multi-monitor - show on second screen
msger -message "Second screen" -pos 0,100 -screen 1

# What displays are there? (JSON, no window; indices match -screen)
msger -list

# Transparent click-through overlay on screen 1, gone after 3 seconds
msger -overlay -fullscreen -screen 1 -timeout 3 "1"

# Number every screen, the way the display settings "Identify" button does
msger -list | ConvertFrom-Json | ForEach-Object { $_.monitors } | ForEach-Object {
    Start-Process msger -ArgumentList "-overlay -fullscreen -screen $($_.index) -timeout 3 `"$($_.index + 1)`""
}

# Auto-close timeout
msger -message "Closing in 5 seconds..." -timeout 5

# Open with DevTools for debugging (automatically opens DevTools panel)
msger -url "https://example.com" -dev

# See all options
msger --help

无头模式( E)-noshow)——以WebView为CSS/JS引擎

-noshow 不打开可见窗口, 但 WebView 仍然装入 HTML, 运行 <script> 块,并解析 CSS —— 这样一个嵌入式脚本就可以查询引擎,并通过 window.ipc.postMessage结合 -result <fieldname> 来打印一个字段,这可以让你使用 msger 作为无头渲染引擎 用于类似的东西 contrast-color(), (中文(简体) ), getComputedStyle(),以及 CSS.supports()。 。 。 .

# Resolve contrast-color() — needs a DOM element + getComputedStyle because
# CSS functions only resolve through the cascade.
msger -noshow -html '<div id=x style="color:contrast-color(steelblue)"></div>
<script>
  requestAnimationFrame(() => requestAnimationFrame(() => {
    window.ipc.postMessage(JSON.stringify({
      button: "r",
      value: getComputedStyle(document.getElementById("x")).color
    }));
  }));
</script>' -result value
# → rgb(255, 255, 255)

节点API同样工作方式——通过 noshow: true 财务报告和审定财务报表 html: "..." 改为 showMessageBox,然后读取 result.value 以坚忍的盟誓盟誓.

注释:

  • -result <fieldname> 打印字段的值(字符串为-is,其他类型为JSON-stringifed),而不是完整 MessageBoxResult 贾森。 用来消耗外壳.
  • 两者 requestAnimationFrame 调用让布局在读取计算样式之前结算——需要用于 contrast-color,渐变等.
  • 原画 -noshow -save 行为没有改变:它保存后仍然退出,从未创建过WebView.

渲染模式( E)-render)——抓取页面到图像

-render 将 msger 转换为无头页面 – bitmap 渲染器: 从未出现过窗口; 页面负载、 结算、 截图和 msger 退出 。 视窗 (WebView2, CDP) Page.captureScreenshot)和Linux/Pi(WebKitGTK快照). 在Mac上没有支持.

# Write a PNG of a web page (format follows the extension: .png/.jpg/.bmp)
msger -url "https://example.com" -size 1024,768 -render page.png

# Render inline HTML (charts, badges, generated markup)
msger -html "<h1 style='color:steelblue'>Build OK</h1>" -size 400,150 -render status.png

# No file → the image comes back base64 in the JSON result
msger -message "hello" -render
# → { "button": "render", "render": { "format": "png", "data": "iVBOR...", "width": 500, "height": 375 } }

节点 API 镜像此:

// Write a file; result.render = { path, width, height, format }
await showMessageBox({ url: "https://example.com", size: { width: 1024, height: 768 }, render: "page.png" });

// Or get the image as an object; result.render = { data (base64), width, height, format }
const result = await showMessageBox({ html: "<h1>Chart</h1>", render: true });
fs.writeFileSync("out.png", Buffer.from(result.render!.data!, "base64"));

注释:

  • 页面之后的捕捉火灾 load 事件+2 requestAnimationFrames + 结算延迟(renderDelay 选项,默认为100ms)。 如果这页从不开火 load,msger在超时(渲染模式中的默认为30s)时抓取最佳效果.
  • Width/height是物理像素——125%的DPI显示抓取500×375上的400×300窗口.
  • renderFormat (单位:千美元)png编号 :jpeg编号 :bmp)可以在API中明确设置;CLI来源于文件扩展名.
  • 一个失败的抓取拒绝了承诺(CLI:stderr上的错误,非零退出).
  • msgview 支持同样的 -render 选项通过 Electron's capturePage() 在它的平台上.
  • -render 抓取 视图 (窗户大小. 要抓取整个文档,包括卷出视图的内容,请使用 缩写+ 移动+S / 在可见窗口中右键单击"保存页面图像"(见键盘快捷键). 该路径只写一个文件到您的 Pictures 文件夹; 任何信息都无法返回呼叫者 .
  • 有一个 没有 API 可按要求抓取活窗口 (从JS通过) msgapi,或者从母进程),并获取图像作为缓冲. 伦德模式为一发:抓取后退出.
  • 只抓取了页面,从不抓取桌面或其他窗口.

(Claude Code更新了第2026-11-05节,Opus 5.5:添加了Linux/Pi,Mac,viewport vs. full page,和缺失的活捉API

JSON 配置文件

您可以将消息框配置存储在 JSON 文件, 以供再使用 。 JSON文件支持注释(JSON5格式).

# Load configuration from file
msger -load config.json

# Override specific values from loaded config
msger -load config.json -title "New Title" -size 800,600

# Save current command-line options to a file (only saves explicitly specified values)
msger -title "My Dialog" -message "Hello" -buttons Yes No -save my-config.json

# Save config without showing the message box (uses -noshow)
msger -title "My Dialog" -message "Hello" -buttons Yes No -save my-config -noshow

# Load base config, override, and save the overrides
msger -load base.json -title "Modified" -save modified.json

# Save and show (saves config then displays the message box)
msger -title "Test" -message "Saving config..." -save test.json

注释:

  • 这个 -save 选项只保存明确指定的命令行参数,而不是衍生出默认值。 这将配置文件保持在最低限度,并允许默认进化.
  • -noshow 与 -save 写入配置和退出而不创建 WebView 。 无 -save, (中文(简体) ), -noshow 创建WebView并运行脚本,但不打开可见窗口——用于无头CSS/JS解析(见下文"无头模式").
  • 文件扩展名: 如果您不指定 .json,将自动添加(例如, myconfig 变成 myconfig.json) (中文(简体) ).

完整的JSON结构

{
    "title": "Window Title",
    "message": "Plain text message (supports ANSI color codes)",
    "html": "<h1>HTML content</h1><p>Rich formatting</p>",
    "url": "https://example.com",
    "hash": "section1",
    "size": {
        "width": 600,
        "height": 400
    },
    "pos": {
        "x": 100,
        "y": 100,
        "screen": 0
    },
    "buttons": ["Cancel", "OK"],
    "defaultValue": "default input text",
    "inputPlaceholder": "Enter text here...",
    "allowInput": false,
    "timeout": 30,
    "autoSize": false,
    "alwaysOnTop": false,
    "fullscreen": false,
    "zoom": 100,
    "debug": false,
    "icon": "path/to/icon.png",
    "dev": false
}

实地参考

外地类型默认说明
title字符串"记忆"窗口标题
message字符串无效纯文本消息( 支持 ANSI 颜色代码)
html字符串无效要显示的 HTML 内容
url字符串无效要装入的 URL (web 或文件 ://)
hash字符串无效添加到 URL( 需要 URL) 的散列片段 。 领跑#是可选的.
size对象{"width": 600, "height": 400}窗口大小
size.width编号600个(或1024个URL)窗口宽度, 像素
size.height编号400个(或768个URL)窗口高度( 像素)
pos对象无效窗口位置
pos.x编号- 说吧X 像素坐标
pos.y编号- 说吧Y 像素坐标
pos.screen编号无效[只有窗口]屏幕指数(0=主,1=秒等)
buttons字符串 []["好吧"]按钮标签
defaultValue字符串无效默认输入值
inputPlaceholder字符串无效输入字段的占位符文本
allowInput布尔虚假显示输入字段
timeout编号无效N 秒后自动关闭
autoSize布尔无大小时为真自动调整窗口以适应内容
alwaysOnTop布尔虚假保持窗口上方
fullscreen布尔虚假以全屏模式启动
screen编号无效监视器指数(基于0) fullscreen后退时 pos.screen。选择显示的可移植方式——Wayland拒绝客户端设置窗口坐标,但在选定的输出上尊重全屏
overlay布尔虚假无框架,透明,点击通过,总是从桌面上取出窗口,远离任务栏,从不集中. 与 timeout ——它没有关闭按钮并经过点击,所以里面没有任何东西可以操作. 与 url编号 :rawHtml 页面必须设置自己的透明背景;内置模板已经设置了。 每个覆盖都获得自己的WebView2配置文件(由屏幕键入),这样可以同时开始一组配置文件
listMonitors布尔虚假打印显示器布局为 JSON 并退出而不打开窗口 : {"monitors":[{index,name,x,y,width,height,scale,primary}]}
zoom编号100个初始缩放水平(100=100%,150=150%). 应用在每个模式——消息、 HTML 和 URL
newWindow字符串"browser"在哪里"在新窗口打开" / target=_blank 链接去 : "browser" (系统浏览器)或 "msger" (弹出另一个msger窗口)
contextMenu字符串"page""always" 将本地右键单击菜单强制到任何地方,即使页面用自己的页面压制它 contextmenu 处理器
showVersion布尔虚假保留 msger vX.Y.Z 标题栏的附件,当页面更改自己的标题时重新应用
debug布尔虚假结果返回调试信息
noResult布尔虚假JSON Studout上的结果( 错误仍为 stderr )
icon字符串无效窗口图标路径 (.png,.ico)
dev布尔虚假自动打开 DevTools( 用于调试 HTML/ URL 内容)

内容优先级 : 仅显示一个内容类型( 按顺序):

  1. url - 如果提供,则装入 URL(ignores message/html)
  2. html - 如果提供,则显示 HTML(ignores 消息)
  3. message - 有 ANSI 颜色支持的纯文本

向后兼容性 : 旧的 width 财务报告和审定财务报表 height 字段(在顶层)仍然支持后向兼容,但 size 对象首选。 如果两者都提供, size 以优先为准.

JSON 实例

简单对话框 :

{
    "title": "Confirm",
    "message": "Are you sure?",
    "buttons": ["Cancel", "OK"]
}

输入对话框 :

{
    "title": "Enter Name",
    "message": "Please enter your name:",
    "allowInput": true,
    "inputPlaceholder": "Your name here",
    "defaultValue": "John Doe",
    "buttons": ["Cancel", "Submit"]
}

HTML 内容 :

{
    "title": "Welcome",
    "html": "<h1>Welcome!</h1><p>Getting started...</p>",
    "size": {
        "width": 700,
        "height": 500
    }
}

在第二个显示器上设置窗口 :

{
    "message": "Second screen",
    "pos": {
        "x": 0,
        "y": 100,
        "screen": 1
    }
}

CLI 选项参考

Usage: msger [options] [message words...]

Options:
  -message, --message <text>      Plain text message
  -title, --title <text>          Window title
  -html, --html <html>            HTML content
  -url, --url <url>               URL to load (web, local file, or directory → its index.html)
  -hash, --hash <fragment>        Hash fragment to append to URL (requires -url). Leading # optional.
  -buttons, --buttons <labels>    Button labels (e.g., -buttons Yes No Cancel)
  -ok, --ok                       Add OK button
  -cancel, --cancel               Add Cancel button
  -input, --input [placeholder]   Include input field with optional placeholder text
  -default, --default <text>      Default value for input field
  -size, --size <width,height>    Window size (e.g., -size 800,600)
  -pos, --pos <x,y>               Window position (e.g., -pos 100,200)
  -screen, --screen <number>      Screen index (0=primary, 1=second, etc.). Offsets -pos into
                                  that screen, and picks which screen -fullscreen covers.
  -list, --list                   Print the monitor layout as JSON and exit (no window)
  -zoom, --zoom <percent>         Zoom level as percentage (e.g., -zoom 150 for 150%).
                                  Works in message, HTML and URL modes alike.
  -newwindow, --newwindow <where> Where "open in new window" links go:
                                  browser (default) or msger (spawn another msger window)
  -timeout, --timeout <seconds>   Auto-close after specified seconds
  -ontop, --ontop                 Keep window always on top
  -detach, --detach               Launch window independently (parent returns immediately)
  -fullscreen, --fullscreen       Start window in fullscreen mode (F11 to toggle, Escape to exit)
  -overlay, --overlay             Frameless, transparent, click-through window over the desktop.
                                  Always on top, no taskbar slot, never takes focus. Pair with
                                  -timeout; combine with -fullscreen -screen <n> per display.
  -raw, --raw                     With -html: load HTML as-is, no msger template/buttons (alias: -full)
  -debug, --debug                 Return debug info (HTML, size, autoSize) in result
  -render, --render [file]        Render the page to a bitmap instead of displaying it.
                                  With <file>, writes the image (.png/.jpg/.bmp by extension);
                                  without, returns it base64 in result.render. [Windows, Linux/Pi]
  -noshow, --noshow               Don't display the window. With -save, exits after saving.
                                  Otherwise the WebView still loads + runs scripts so a page
                                  can post a result via window.ipc.postMessage; only the
                                  window isn't shown. Useful for headless CSS/JS resolution.
  -noresult, --noresult           Suppress JSON result output on stdout (errors still go to stderr)
  -result, --result [fieldname]   Re-enable result output. With <fieldname>, print just that
                                  field (e.g. -result value → bare string). Strings print as-is,
                                  other types JSON-stringify. Missing field → exit 2.
  -v, -version, --version         Show version number
  -help, -?, --help               Show help message

Keyboard Shortcuts:
  - Enter: Click default (last) button
  - Escape: Dismiss dialog or exit fullscreen
  - F11: Toggle fullscreen mode
  - F12: Open developer tools (DevTools/Inspect)
  - Ctrl+Wheel/Plus/Minus: Zoom in/out (×1.25 per step, so in-then-out returns
    exactly to where you started). The host owns the zoom factor — the system
    menu's zoom items, -zoom and these keys all drive the same value.
  - Ctrl+0: Reset zoom to 100%
  - Ctrl+Shift+S: Save an image of the WHOLE page — including whatever is
    scrolled out of view — to your Pictures folder. The path is printed to
    stderr and copied to the clipboard (Windows). Also on the right-click menu
    as "Save page image".

Debug Mode:
  - Set environment variable MSGER_DEBUG=1 for diagnostic output
  - Shows: startup info, keyboard events, IPC messages, button clicks
  - Example (PowerShell): $env:MSGER_DEBUG=1; msger "Test"
  - Zero performance impact when disabled

Notes:
  - If no options provided, all non-option arguments are concatenated as message
  - Press ESC to dismiss (returns button: "dismissed")
  - Press Enter to click last (default) button
  - OK button is green by default
  - URLs default to 1024x768 window size
  - Window title automatically updates from loaded page's <title> tag when using -url
  - Local pages given to -url are served from their own directory over
    http://msger.localhost/ rather than file:// (file:// pages cannot use the
    msgapi IPC bridge at all — WebView2 aborts on them)
  - Right-click → "Copy URL" copies the address of the current page; for local
    content it copies the file's path on disk
  - The loaded page's favicon becomes the window + taskbar icon (Windows);
    pass -icon to keep your own icon instead
  - Windows auto-size to fit content when size not specified
  - Runtime zoom: Ctrl+Wheel, Ctrl+Plus, Ctrl+Minus

节点.js API 参考

在您的 Node.js 或 TypeScript 应用程序中使用 msger , 并使用简单的基于 API 的 Profession .

快速启动

import { showMessageBox } from '@bobfrankston/msger';

const result = await showMessageBox({
    title: 'Confirm Action',
    message: 'Are you sure you want to proceed?',
    buttons: ['Cancel', 'OK']
});

console.log('User clicked:', result.button);

if (result.value) {
    console.log('User entered:', result.value);
}

程序关闭 API (New!)

从父进程程序上关闭消息框 :

基于处理的 API( 建议):

import { showMessageBoxEx } from '@bobfrankston/msger';

const handle = showMessageBoxEx({
    message: 'Processing...',
    buttons: ['Cancel']
});

console.log('Dialog PID:', handle.pid);

// Close after 5 seconds
setTimeout(() => {
    handle.close();
}, 5000);

// Wait for result
const result = await handle.result;
// Result: {button: 'closed', closed: true} if closed programmatically
// Result: {button: 'Cancel'} if user clicked Cancel

独立的近距离函数 :

import { showMessageBoxEx, closeMessageBox } from '@bobfrankston/msger';

const handle = showMessageBoxEx({ message: 'Working...' });
const pid = handle.pid;

// Close by PID from anywhere
closeMessageBox(pid);

使用大小写 :

  • 任务完成后自动关闭的进程对话框
  • 基于超时的通知
  • PID 管理多个对话框
  • 离线对话框远程关闭

见 关闭-API.md 用于完整文档.

API 函数

showMessageBox(options: MessageBoxOptions): Promise<MessageBoxResult>

显示消息框对话框并等待用户回复 .

信件框选项

interface MessageBoxOptions {
    title?: string;           // Window title (default: "Message")
    message?: string;         // Plain text message (optional if url or html provided)
    html?: string;            // HTML content to display
    url?: string;             // URL to load (web URL or file:// path)
    hash?: string;            // Hash fragment to append to URL (requires url). Leading # optional.
    size?: {                  // Window size in pixels
        width: number;        // Window width (default: 600, or 1024 for URLs)
        height: number;       // Window height (default: 400, or 768 for URLs)
    };
    pos?: {                   // Window position
        x: number;            // X coordinate in pixels
        y: number;            // Y coordinate in pixels
        screen?: number;      // [Windows only] Screen index (0=primary, 1=second, etc.)
    };
    buttons?: string[];       // Button labels (default: ["OK"])
    defaultValue?: string;    // Default input value
    inputPlaceholder?: string; // Placeholder text (gray hint) for input field
    allowInput?: boolean;     // Show input field (default: false)
    autoSize?: boolean;       // Auto-resize window to fit content (default: true when no size specified)
    alwaysOnTop?: boolean;    // Keep window on top of other windows (default: false)
    zoom?: number;            // Initial zoom level (100=100%, 150=150%, 50=50%)
    timeout?: number;         // Auto-close after N seconds
    detach?: boolean;         // Launch detached from parent process
    fullscreen?: boolean;     // Start window in fullscreen mode (F11 to toggle)
    rawHtml?: boolean;        // With html: load HTML as-is, no msger template/buttons (used by mdview). CLI: -raw
    debug?: boolean;          // Return debug info (HTML, size, autoSize) in result
    noResult?: boolean;       // Suppress JSON result on stdout (CLI: -noresult, -result re-enables)
    render?: boolean | string; // Render to a bitmap instead of displaying. String = file to write
                               // (format from extension), true = base64 object in result.render.
    renderDelay?: number;     // Render mode: ms between page load and capture (default 100)
    renderFormat?: string;    // Render mode: png (default) | jpeg | bmp
}

信件框结果

interface MessageBoxResult {
    button: string;       // Label of clicked button
    value?: string;       // Input value (if allowInput was true)
    form?: object;        // Form data (if form elements present)
    closed?: boolean;     // True if closed programmatically via handle.close()
    dismissed?: boolean;  // True if user pressed Escape
    timeout?: boolean;    // True if closed due to timeout
    bounds?: {            // Virtual-desktop window geometry at close (pixels).
                          // x,y are single-plane coords across all monitors — NOT
                          // monitor-relative + screen index. Feed straight back into
                          // `-pos bounds.x,bounds.y`. See msgcommon/README.md.
        x: number;
        y: number;
        width: number;
        height: number;
    };
    debug?: {             // Debug info (if debug option was true)
        html: string;     // Generated HTML content
        width: number;    // Window width
        height: number;   // Window height
        autoSize: boolean; // Whether auto-sizing is enabled
    };
    render?: {            // Captured screenshot (render mode)
        format: string;   // png | jpeg | bmp
        width: number;    // Physical pixels (includes DPI scale)
        height: number;
        data?: string;    // Base64 image bytes (render: true)
        path?: string;    // Absolute path of written file (render: "file")
    };
    renderError?: string; // Why render produced no image (the promise rejects with this)
}

API 示例

简单确认对话框

const result = await showMessageBox({
    title: 'Delete File',
    message: 'Are you sure you want to delete this file?',
    buttons: ['Cancel', 'Delete']
});

if (result.button === 'Delete') {
    // Perform deletion
}

输入对话框

const result = await showMessageBox({
    title: 'Enter Name',
    message: 'Please enter your name:',
    allowInput: true,
    inputPlaceholder: 'Your name here',
    defaultValue: 'John Doe',
    buttons: ['Cancel', 'OK']
});

if (result.button === 'OK') {
    console.log('Name entered:', result.value);
}

HTML 内容

const result = await showMessageBox({
    title: 'Welcome',
    html: `
        <div style="font-family: sans-serif;">
            <h2 style="color: #2563eb;">Welcome!</h2>
            <p>This supports <strong>HTML</strong> content.</p>
            <ul>
                <li>Rich formatting</li>
                <li>Custom styles</li>
                <li>Any HTML elements</li>
            </ul>
        </div>
    `,
    size: { width: 700, height: 500 },
    buttons: ['Close']
});

ANSI 颜色代码

纯文本信息自动支持 ANSI 色彩逃逸序列, 这些序列被转换为 HTML , 并带有适当的颜色 :

const result = await showMessageBox({
    title: 'Color Test',
    message: '\x1b[31mRed text\x1b[0m\n\x1b[32mGreen text\x1b[0m\n\x1b[1m\x1b[34mBold blue\x1b[0m',
    buttons: ['OK']
});

支持的 ANSI 代码 :

  • 颜色:红(31),绿(32),黄(33),蓝(34),红(35),青(36),白(37)
  • 样式: 粗体(1),下行(4),重置(0)
  • 背景情况: 40-47 (与前缘同色号)

CLI 实例 :

echo -e "\x1b[31mError:\x1b[0m Something went wrong" | msger

显示网页

// Load external website
// Note: Window title automatically updates from page's <title> tag
await showMessageBox({
    url: 'https://github.com/BobFrankston/msger',
    size: { width: 1024, height: 768 }
});

// Load local HTML file
await showMessageBox({
    url: 'file:///path/to/help.html',
    size: { width: 800, height: 600 }
});

// Load with DevTools opened automatically (for debugging)
await showMessageBox({
    url: 'https://example.com',
    dev: true,  // Opens DevTools automatically
    size: { width: 1024, height: 768 }
});

自动关闭超时

// Show notification that auto-closes after 3 seconds
// A translucent countdown indicator appears in the top-right corner
const result = await showMessageBox({
    title: 'Notification',
    message: 'File saved successfully!',
    timeout: 3,
    buttons: ['OK']
});

if (result.timeout) {
    console.log('Notification auto-closed');
}

倒计时器在右上角显示为微妙的黄色徽章,显示所剩秒(如"10","9","8"等).

HTML 窗体

const result = await showMessageBox({
    title: 'User Registration',
    html: `
        <form>
            <label>Name: <input name="name" required /></label><br>
            <label>Email: <input name="email" type="email" required /></label><br>
            <label>Age: <input name="age" type="number" /></label>
        </form>
    `,
    buttons: ['Cancel', 'Submit']
});

if (result.button === 'Submit' && result.form) {
    console.log('Name:', result.form.name);
    console.log('Email:', result.form.email);
    console.log('Age:', result.form.age);
}

窗口定位

// Position at specific coordinates
await showMessageBox({
    message: 'Positioned window',
    pos: { x: 100, y: 100 }
});

// Position on second monitor (Windows only)
await showMessageBox({
    message: 'On second screen',
    pos: { x: 0, y: 100, screen: 1 }
});

总是在顶部缩放( Z)

// Keep window on top with 150% zoom
await showMessageBox({
    title: 'Important Alert',
    message: 'This window stays on top!',
    alwaysOnTop: true,
    zoom: 150
});

自动缩放窗口

// Window automatically sizes to fit content
await showMessageBox({
    message: 'Short message',
    autoSize: true  // default when size not specified
});

已调试的 URL 浏览器

// Launch URL window that stays open after script exits
await showMessageBox({
    url: 'https://example.com',
    size: { width: 1200, height: 800 },
    detach: true,
    alwaysOnTop: true
});
// Script continues/exits immediately, window stays open

全屏模式

// Launch window in fullscreen mode (like F11 in browser)
await showMessageBox({
    url: 'https://example.com',
    fullscreen: true
});
// Users can press F11 to toggle fullscreen or Escape to exit

// Fullscreen with message
await showMessageBox({
    message: 'Full screen presentation',
    fullscreen: true,
    buttons: ['Close']
});

特征

  • QQ 显示纯文本、 HTML 内容或装入 URL
  • QQ 完整 HTML/ CSS 支持
  • * ANSI 颜色代码(彩色终端输出)
  • QQ 自定义按钮
  • 输入字段和表格
  • QQ 自动关闭超时
  • 窗口定位和大小
  • 多监视器支持( Windows)
  • 总是在顶端模式
  • 缩放控制
  • QQ 全屏模式
  • QQ 类型脚本类型定义
  • 键盘快捷键( Enter, Escape, F11, F12)

为什么是Msger?

  • 快点 -200米以下的开口
  • 小型 - 只安装了几台MB
  • 简单 - 简便承诺的API
  • 弹性 - 纯文本、 HTML 或装入 URL
  • 跨平台 - 在Windows和Linux上工作

技术细节和业绩计量,见 最不发达国家。 。 。 .

msg 对 msgview 编辑器

这个包是 粗糙/粗糙 执行。 还有 @bobfrankston/ msgview 页面存档备份,存于互联网档案馆 - 具有相同API的以电子为基础的替代品.

侧面msger (这个)磁盘视图
启动~50-200 ms (单位:千米)~2-3秒
大小~5-10MB (5-10MB)~200MB 键
技术Rust + wry (WebView2/webkit2gtk) (中文(简体) )电子
皮/ 林纳编导问题完美无缺
视窗/ WSL 维基月球工作时间工作时间

何时使用 msger( 此软件包)

  • 速度至关重要(CLI工具、自动化)
  • 小二进制大小问题
  • Windows 或 WSL 环境

何时使用 msgview

  • 运行在 Raspberry Pi 或 Linux 上
  • 需要可靠的跨平台渲染
  • 偏好电能生态系统

窗口。 msgapi

msger 注射剂 window.msgapi 输入已装入的页面 msger-api.js,提供窗口控制, DNS 查找(msgapi.dns.lookup,添加了2026-09-17),UDP网络化(host 可能是IP或主机名-同解析器),而HTTP取取. 文件系统和 shell 操作尚未在 msger 中执行 .

见 msgapidefs 读取ME 全文 window.msgapi API参考文献,执行状况及安全说明. API是实验性的,可以改变.


补充资料

重要说明

任务栏图标

图标行为差异 :

  • 窗口标题栏: 显示自定义图标 -icon 旗帜或 JSON 配置
  • Windows 任务栏: 显示嵌入式 msger.exe 图标(运行时无法更改)

这是本地应用程序的Windows限制. 任务栏图标来自可执行器的嵌入资源,而不是运行时窗口图标. 相形之下,基于Electron的msgview可以动态地设置任务栏图标.

工作间: 计划 -pin appUserModelID 特性将允许每个被绑定的快捷键拥有自己的任务栏图标.

警卫

⚠️ msger 用于显示可信、友好的内容 (本地应用程序,您的 HTML 文件). 它不是一个安全沙盒,用于不可信/敌对的网络内容。 使用 -htmlfrom 财务报告和审定财务报表 -url 仅限信任来源.

mSG 爪哇脚本 API

最小 API - 大多数功能使用本地浏览器 API:

  • msger.isAvailable() - 特征检测(Msger的返回真实)
  • msger.close() - 一样 window.close() (首选本地API)

建议: 使用本地浏览器 API(localStorage, (中文(简体) ), window.close()为相容性。 代码会在任何浏览器上下文中工作,而不仅仅是MSger.

对于开发者

许可证

公务员制度委员会

作者

鲍勃·弗兰克斯顿

版本与发布记录

@bobfrankston/msger 共发布 419 个版本,首次发布于 2025/10/23;过去 12 个月发布了 348 个版本。

版本发布日期距今
0.1.436latest2026/11/07今天
0.1.4352026/10/2811 天前
0.1.4342026/09/221 个月前
0.1.4332026/09/181 个月前
0.1.4322026/09/181 个月前
0.1.4312026/09/062 个月前

关于 @bobfrankston/msger 的常见问题

@bobfrankston/msger 是什么?

快速, 轻量级, 跨平台的信息框 - Rust 动力替代 msgview

如何安装 @bobfrankston/msger?

在项目目录运行 npm install @bobfrankston/msger,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 msger,可以用 npx msger 直接运行。

@bobfrankston/msger 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bobfrankston/msger 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@bobfrankston/msger 可以商用吗?

@bobfrankston/msger 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bobfrankston/msger 的下载量有多少?

根据 npm 官方下载统计,@bobfrankston/msger 在 2026/10/09 – 2026/11/07 这 30 天内被下载 4,103 次,日均约 137 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bobfrankston/msger 还在维护吗?

最新版本 0.1.436 发布于 2026/11/07(今天);至今共发布 419 个版本,其中过去 12 个月发布了 348 个;首次发布于 2025/10/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。