Coverage for sources/mimeogram/interfaces.py: 79%

24 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-03 00:13 +0000

1# vim: set filetype=python fileencoding=utf-8: 

2# -*- coding: utf-8 -*- 

3 

4#============================================================================# 

5# # 

6# Licensed under the Apache License, Version 2.0 (the "License"); # 

7# you may not use this file except in compliance with the License. # 

8# You may obtain a copy of the License at # 

9# # 

10# http://www.apache.org/licenses/LICENSE-2.0 # 

11# # 

12# Unless required by applicable law or agreed to in writing, software # 

13# distributed under the License is distributed on an "AS IS" BASIS, # 

14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 

15# See the License for the specific language governing permissions and # 

16# limitations under the License. # 

17# # 

18#============================================================================# 

19 

20 

21''' Abstract bases and interfaces. ''' 

22 

23 

24from __future__ import annotations 

25 

26from . import __ 

27from . import parts as _parts 

28 

29 

30class CliCommand( # pylint: disable=invalid-metaclass 

31 __.typx.Protocol, 

32 metaclass = __.ImmutableStandardProtocolDataclass, 

33 decorators = ( __.standard_dataclass, __.typx.runtime_checkable ), 

34): 

35 ''' CLI command. ''' 

36 

37 @__.abc.abstractmethod 

38 async def __call__( self, auxdata: __.Globals ) -> None: 

39 ''' Executes command with global state. ''' 

40 raise NotImplementedError 

41 

42 @__.abc.abstractmethod 

43 def provide_configuration_edits( self ) -> __.DictionaryEdits: 

44 ''' Provides edits against configuration from options. ''' 

45 raise NotImplementedError 

46 

47 

48class DifferencesDisplay( # pylint: disable=invalid-metaclass 

49 __.typx.Protocol, 

50 metaclass = __.ImmutableStandardProtocolDataclass, 

51 decorators = ( __.standard_dataclass, __.typx.runtime_checkable ), 

52): 

53 ''' Configuration for content differences display. ''' 

54 

55 context_lines: int = 3 

56 inline_threshold: int = 24 # TODO? Adjust to terminal height. 

57 # TODO: colorize: bool = False 

58 # TODO: emojify: bool = False 

59 # TODO: show_whitespace: bool = False 

60 # TODO: truncate_lines: bool = False 

61 # TODO: wrap_lines: bool = False 

62 

63 @__.abc.abstractmethod 

64 async def __call__( self, lines: __.cabc.Sequence[ str ] ) -> None: 

65 ''' Displays differences segment. ''' 

66 raise NotImplementedError 

67 

68 

69class DifferencesInteractor( # pylint: disable=invalid-metaclass 

70 __.typx.Protocol, 

71 metaclass = __.ImmutableProtocolClass, 

72): 

73 ''' Interactions with content differences. ''' 

74 

75 @__.abc.abstractmethod 

76 async def __call__( 

77 self, lines: __.cabc.Sequence[ str ], display: DifferencesDisplay 

78 ) -> bool: 

79 ''' Prompts for action on differences segment. ''' 

80 raise NotImplementedError 

81 

82 

83class PartInteractor( # pylint: disable=invalid-metaclass 

84 __.typx.Protocol, 

85 metaclass = __.ImmutableStandardProtocolDataclass, 

86 decorators = ( __.standard_dataclass, __.typx.runtime_checkable ), 

87): 

88 ''' Interactions with mimeogram parts. ''' 

89 

90 @__.abc.abstractmethod 

91 async def __call__( 

92 self, target: _parts.Target 

93 ) -> tuple[ _parts.Resolutions, str ]: 

94 ''' Prompts for action on mimeogram part. ''' 

95 raise NotImplementedError