diff options
| author | TitanSnow <[email protected]> | 2017-04-30 12:28:47 +0800 |
|---|---|---|
| committer | TitanSnow <[email protected]> | 2017-04-30 12:29:43 +0800 |
| commit | 73eea1fccb4e11f3678eaddaad22cae5ab79106c (patch) | |
| tree | 56c06f69df8dfb331c941cf2ec975fa71b616ae9 /core/src/xmake/os | |
| parent | 90d69cadfa5f5846e311876bfbd4a298c666fc8e (diff) | |
add os.getwinsize()
Diffstat (limited to 'core/src/xmake/os')
| -rw-r--r-- | core/src/xmake/os/getwinsize.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/core/src/xmake/os/getwinsize.c b/core/src/xmake/os/getwinsize.c new file mode 100644 index 000000000..c541f1e0e --- /dev/null +++ b/core/src/xmake/os/getwinsize.c @@ -0,0 +1,72 @@ +/*!The Make-like Build Utility based on Lua + * + * 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. + * + * Copyright (C) 2015 - 2017, TBOOX Open Source Group. + * + * @author TitanSnow + * @file getwinsize.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "getwinsize" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" +#ifdef TB_CONFIG_OS_LINUX +#include <sys/ioctl.h> +#include <termios.h> +#include <unistd.h> +#endif + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_os_getwinsize(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + // def w&h + unsigned short w=80, h=40; + + // get winsize +# ifdef TB_CONFIG_OS_LINUX + struct winsize size; + ioctl(STDOUT_FILENO, TIOCGWINSZ, &size); + w=size.ws_col; + h=size.ws_row; +# endif + + // done os.getwinsize() + lua_newtable(lua); + lua_pushstring(lua, "width"); + lua_pushinteger(lua, w); + lua_settable(lua, -3); + lua_pushstring(lua, "height"); + lua_pushinteger(lua, h); + lua_settable(lua, -3); + + // ok + return 1; +} |
