# Copyright (C) 2012,2017 G.P. Halkes
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

types {
	map {
		type = "section"
		allowed-keys {
			_use { type = "list"; item-type = "use" }
			_noticheck {
				type = "list";
				item-type = "string";
			}
			_ticheck { type = "bool" }
		}
		# For enter and leave, strings starting with \ are assumed to be
		# literals. Otherwise they are assumed to be terminfo capnames
		item-type = "string"
	}

	use {
		type = "string"
		%constraint = "{undefined map in 'use'} /maps/[%]"
	}

	shiftfn-int {
		type = "int"
		%constraint = "{'shiftfn' values must be between 1 and 255} % > 0 & % < 256"
	}
}

allowed-keys {
	format { type = "int" }
	best { type = "use" }
	aka { type = "list"; item-type = "string" }
	shiftfn {
		type = "list"
		item-type = "shiftfn-int"
		%constraint = "{'shiftfn' expects a list of 3 integers} # = 3"
	}
	xterm_mouse { type = "bool" }

	maps {
		type = "section"
		item-type = "map"
	}

	add {
		type = "list"
		item-type = "map"
	}
}
%constraint = "{format must be one} format = 1"
%constraint = "{both 'best' key and 'maps' section must be present} best & maps"
%constraint = "{'best' must name an existing map} /maps/[best]"

# Further checks which can not be implemented with constraints:
# - only the first occurence of a sequence is used

# FIXME: the following is not implemented yet.
# Example key addition (this would be in the user's home directory)
# %include = "xterm"
# %add {
#		add-to = "%best" # without this key, it will add to any map loaded
#		home-s = "\eOA"
#		end-s = \eOE"
# }
