Code Monkey home page Code Monkey logo

Comments (3)

endaaman avatar endaaman commented on May 20, 2024 1

DRAFT1: New style configuration

Here is an overview.

config.lua

-- use `require`, do not define in global implicitly
local tym = require('tym') 

local home = os.getenv('HOME')

-- set config using table
tym.set_config({
  width = 120,
  shell = home .. '/bin/tmux-attach-or-new',
  title = 'tym',
  cursor_blink_mode = 'off',
  cjk_width = 'narrow',
  ignore_default_keymap = false,
  -- use theme
  -- if true, theme loading will be skipped after loading config
  ignore_theme = false,
})

-- get value
print(tym.get('height'))

-- set single value
tym.set('height', 40)

-- default `nil` so get nil
local y = tym.get('role')

-- get nil and warning printed
local x = tym.get('not exist')

-- only warning and no effect
tym.set('not exist', 123)

-- clear all custom keymaps
tym.reset_keymaps()

-- set keymap using table
tym.set_keymaps({
  ['<Ctrl><Shift>1'] = function()
    -- simply load this script
    -- config on that time will be keeped and overwritten
    tym.reload()
    tym.notify('reset and loaded')
  end,
  ['<Ctrl><Shift>2'] = function()
    -- restore default config
    tym.reset()

    -- certainly, get default value
    print(tym.get('height'))
  end,
})

-- set keymap individually
tym.set_keymap('<Ctrl><Shift>j', function()
  local h = tym.get('height')
   -- the value will not be applied immediatelly
  tym.set('height', h + 2)   
  -- you need to do below
  tym.apply()
end)

tym.set_keymap('<Ctrl><Shift>t', function()
  -- reload theme. if `ignore_theme` is true, do nothing
  -- if true provided like `tym.reload_theme(true)`, reset theme before reload
  tym.reload_theme()
end)

-- custom event handler
tym.set_hook('bell', function()
  print('got bell')
end)

-- by table
tym.set_hooks({
  focus_in = function()
    print('focus in')
  end,
  focus_out = function()
    print('focus out')
  end,
})



-- after excuting `config.lua`, `theme.lua` will be evaluated and the theme will be applied if `ignore_theme` is not true

theme.lua

Simply return theme table

local fg = '#d0d0d0'
local bg = '#181818'
return {
  color_foreground           = fg,
  color_background           = bg,
  color_cursor               = fg,
  --- SNIP
  color_0  = '#181818',
  color_1  = '#ac4142',
  --- SNIP
  color_15 = '#f5f5f5',
}

from tym.

endaaman avatar endaaman commented on May 20, 2024

DRAFT1 was adopted to v2 almost as it is. But there are something changed.

  • theme was add to config instead of ignore_theme.
  • hook feature was postponed to v2.1

from tym.

endaaman avatar endaaman commented on May 20, 2024

Implementation was done.

from tym.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.