百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
I

ImTerm

> 编程语言
开源

仅包含头文件的 c++17 库,用于实现 imgui 应用程序的终端

199 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

仅包含头文件的 c++17 库,用于实现 imgui 应用程序的终端

Table of Contents

  • About ImTerm
    • Features
    • How to include in your project
  • How does it work
    • Basic usage
      • TerminalHeplers
      • command_type
    • Tuning
      • colors and text
      • non-ascii characters
      • spdlog integration
      • extra
  • Author
  • License

About ImTerm

ImTerm is a header only "terminal" library for ImGui, intended to help you build a debug console for your application. ImTerm does not implement commands on its own, but tries to make it easier to have a nice feeling terminal where you can type in your custom commands, and aims to be utf8 friendly. It also comes with an optional spdlog integration if you happen to use it.

Features

ImTerm features revolves mainly around completion:

  • basic tab completion
  • contextual tab completion
  • OSD for completion
  • history completion support, expanding on a tab press
    • !! refers to previous command
    • !-n refers to nth command, starting from the last one
    • !:m refers to mth argument of last command, (with m=0, you are referring to the last command name)
    • !-n:m refers to the mth argument of the nth command, starting from the last command
  • prefixed history search (type your prefix, hit the arrow keys, and you're done!).

If you want to type in !: or !! if your command argument, you'll have to escape one of the exclamation marks with \

Typing command_name Hello, World! will call command_name with two arguments, Hello, and World!. To merge the two arguments, simply add surrounding quotes: command_name "Hello, World!".

How to include in your project

ImTerm only has ImGui as mandatory dependency, and has spdlog as an optional depency. If you use spdlog, then you'll get an easier integration, otherwise that's not a problem, and you won't need to add spdlog to your project.

Since ImTerm is a header only library, appart from its ImGui dependency (that you probably already use if you came there) you'll just need to get ImTerm headers, #include , and you should be done!

ImTerm requires C++17 or above.

How does it work

Basic usage

command_type and argument_type

Adding commands to an ImTerm::terminal is done via the types command_type_cref, command_type and argument_type

The command_type type (which I should rather call ImTerm::command_t>) is a structured used to represent a command, and contains the following attributes:

  • the command name name (as an std::string_view)
  • a short description of the command(as an std::string_view)
  • the command callback (as a function pointer)
  • the completion callback (as a function pointer)

command_type_cref is the type std::reference_wrapper (ie: a const reference that you can store in a vector).

The command callback function can do whatever it wants and takes as a parameter an argument_t>, containing:

  • a reference to your custom argument (of type TerminalHelper::value_type, can be void)
  • a reference to the terminal instance that called the method
  • the list of arguments (including the command name), as an std::vector

The completion callback function takes the same type of argument and should return an std::vector containing a list of possible contextual completion (you may return an empty vector if you don't want to autocomplete user's inputs).

TerminalHelpers

To use ImTerm::terminal's class, you must supply it a TerminalHelper. The TerminalHelper class is responsible for command management. Because It is expected that your commands will need some kind of argument to interact with the rest of your application, your TerminalHelper must define the type TerminalHelper::value_type. That value will be passed to your commands as part of their arguments.

It must implement the following methods:

  • std::vector find_command_by_prefix(std::string_view prefix), which shall return the list of commands starting by prefix (you might want to use ImTerm::misc::prefix_search)
  • std::vector find_command_by_prefix(const char* beg, const char* end), which shall return the list of commands starting by the string formed by [beg, end) (that might just disappear from the needed methods soon)
  • std::vector list_commands(), which shall return the list of all commands
  • std::optional format(std::string msg, message::type msg_type), which shall format a string to your liking, or return an empty optional so that it won't be logged (ImTerm::terminal will invoke this methods when it wants to emit feedback to the user).

Of course, it's a bit of a bummer to have to implement all those methods, so if you want you can also simply inherit from ImTerm::basic_terminal_helper (defined in imterm/terminal_helpers.hpp), which does all that for you. Afterward, you just have to add your commands using basic_terminal_helper::add_command_(const command_type&)

Here is a basic example of what a TerminalHelper can look like:

cpp
	class terminal_helper_example : ImTerm::basic_terminal_helper {
	public:
		static std::vector no_completion(std::string_view) { return {}; }
		
		// clears the logging screen. argument_type is aliased in ImTerm::basic_terminal_helper
		static void clear(argument_type& arg) {
			arg.term.clear();
		}

        // prints the text passed as parameter to the logging screen. argument_type is aliased in ImTerm::basic_terminal_helper
		static void echo(argument_type& arg) {
			if (arg.command_line.size() & term)``.
This method will be invoked right after the instantiation of ImTerm::terminal if it exists, and the passed reference will be valid throughout the whole lifetime of
the terminal.

# Author
Lucas Lazare, a computer engineering student.

# License

This project is under the MIT license.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C++imguilibrarymodern-cpp

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言