1 Star 1 Fork 1

小鱼干 / cMENU

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

cMENU

可以简单的创建一个终端菜单的工具

目录

使用方法

欢迎使用 cMENU

构建

您可以使用以下的方法来将cMENU添加至您的项目中

将源码文件添加至您的项目中

整个cMENU工具仅含有两个文件,您可以直接将 menu.hmenu.c 添加到您的项目中并开始使用. 可以使用如下方式来将cMENU添加至您的源代码中

#include "menu.h"

为了尽可能多的支持各种平台和编译器,cMENU是使用ANSI C (C89)标准编写。

数据结构

cOPTION 代表了一个选项对象 cMENU 代表了一个菜单对象

cOPTION

/* The cOPTION structrue: */
typedef struct _one_option cOPTION;
typedef struct _one_option
{
    char *text;
    cMENU *parent_menu;
    cMENU *next_menu;
    int (*function)(void);
}cOPTION;

您可以使用 mk_option(char*,function) 函数来创建一个option对象(function参数为一个函数的函数名,且该函数为int类型,且无参数) 您可以使用以下方式来创建一个选项列表(选项列表是创建菜单的必要参数):

cOPTION option_list[N]={
    mk_option("option1",func1),
    mk_option("option2",func2),
    ...
    mk_option("optionN",funcN),
}

cMENU

/* The cMENU structrue */
typedef struct _menu cMENU;
typedef struct _menu
{
    char *name;
    char *text;
    struct _menu *parent_menu;
    cOPTION *options_list;
    int option_number;
    boolean back_available;
}cMENU;

您可以使用 mk_menu(char*,char*,cMENU*,cOPTION*,int,boolean)函数来创建一个option对象(通常来说,推荐您在第三个参数处始终使用 NULL) 可以使用下述方式来创建一个菜单对象

cMENU menu = mk_menu("menu_title","menu_introduction",NULL,option_list,N,TRUE);

使用 cOPTION 和 cMENU

cMENU 中的构建方式

  • cMENUmk_menu 构建
  • cOPTIONmk_option 构建
  • cOPTION[] 推荐使用以下方式构建:
cOPTION option_list[N] = {
    mk_option,
    mk_option,...
}

如果你希望修改cMENU中的一些已有的字符串常量

  • modify_system_speaker modify_system_speaker(char*) 可以修改菜单系统对自己的说明默认为:<|系统提示|>
  • modify_menu_reminder modify_menu_reminder(char*) 可以修改菜单中菜单说明的提示符,默认为: 菜单说明
  • modify_whether_remind modify_whether_remind(char*) 可以修改在错误输入后对是否重新输入的提示符,默认为是否重新输入
  • modify_input_remind modify_input_remind(char*) 可以修改系统对请求选项的提示符,默认为 请输入选项
  • modify_back_choice modify_back_choice(char*) 可以修改系统对返回选项的描述,默认为 返回上层菜单
  • link_menu2option 如果您希望在选项执行结束后可以去到下一个菜单,请使用 link_menu2option 函数,将某个选项与某个菜单链接。这样在该选项执行结束后会跳转至该菜单。

选项功能函数的规范

你可以创建函数给选项使用,在用户选择该选项后,会自动执行该函数.如果选项不需要执行某些功能,请在构造时将其功能函数参数处使用NONE_OPTION_FUNC参数:mk_option("**",NONE_OPTION_FUNC)(NONE_OPTION_FUNC). 功能函数编写规范.

int func_name(void)
{
    statements;
    return NORMAL;//如果返回值为NORMAL 则会正常进入下一级菜单
    /*return BACK; //如果返回值为BACK 则会退回到原菜单
}

开始cMENU菜单

  • start 如果你已经完成了菜单的构建,并准备启动该菜单,您可以使用 start(cMENU*)函数来启动菜单.该函数需要您指定最初的菜单.如果菜单正常结束. start函数将会返回0 .

开源声明

MIT License

Copyright (c) 2009-2017 GuoZi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

  • 果子 (original author)
MIT License Copyright (c) 2020 肖永杲-2019211902-2019211408 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

可以简单的创建一个终端菜单的工具 展开 收起
C
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C
1
https://gitee.com/bupt_xyg/cMENU.git
git@gitee.com:bupt_xyg/cMENU.git
bupt_xyg
cMENU
cMENU
master

搜索帮助